diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2018-06-24 21:06:45 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2018-06-24 21:06:45 +0200 |
commit | 1dea27eeaf888a48638c6975e9898fae532b87d2 (patch) | |
tree | 3ca92a48f549ead1b4238d111533d3c2689642ec /miniasm | |
parent | bfba16c5074686a5f5252312cc6aa9d19fd375e2 (diff) | |
download | compilertests-1dea27eeaf888a48638c6975e9898fae532b87d2.tar.gz compilertests-1dea27eeaf888a48638c6975e9898fae532b87d2.tar.bz2 |
some work on the lexer of minic (reading comments)
Diffstat (limited to 'miniasm')
-rw-r--r-- | miniasm/scan.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/miniasm/scan.c b/miniasm/scan.c index ab8dffb..00f9f4e 100644 --- a/miniasm/scan.c +++ b/miniasm/scan.c @@ -29,13 +29,14 @@ static char get_char( Scanner *s ) c = *s->pos; s->pos++; + s->peek = c; return c; } static void skip_whitespace( Scanner *s ) { - for( ; ; s->peek = get_char( s ) ) { + for( ; ; get_char( s ) ) { s->col++; if( s->peek == ' ' || s->peek == '\t' ) { continue; @@ -55,7 +56,7 @@ void scanner_skip_line( Scanner *s ) { while( s->peek != '\0' && s->peek != '\n' ) { s->col++; - s->peek = get_char( s ); + get_char( s ); } if( s->peek == '\n' ) { @@ -72,8 +73,8 @@ Symbol get_int( Scanner *s ) do { sym.data.n = sym.data.n * 10 + ( s->peek - '0' ); - s->peek = get_char( s ); - } while( isdigit( s->peek ) && ( s->peek != '\0' ) ); + get_char( s ); + } while( s->peek != '\0' && isdigit( s->peek ) ); return sym; } @@ -89,12 +90,12 @@ Symbol get_ident_or_label( Scanner *s ) do { *p++ = s->peek; - s->peek = get_char( s ); + get_char( s ); } while( ( isalnum( s->peek ) || s->peek == '_' ) && !isspace( s->peek ) && ( s->peek != '\0' ) && ( s->peek != ':' ) && ( p - newSym.data.s < MAX_IDENT_LEN ) ); if( s->peek == ':' ) { newSym.sym = S_label; - s->peek = get_char( s ); + get_char( s ); } *p = '\0'; |