diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2018-06-25 07:16:11 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2018-06-25 07:16:11 +0200 |
commit | 93815e0c124b4f05043cf6c4c91a3f8cef17f34e (patch) | |
tree | 353c970e11f9d3db608c16cb919761942b536c13 /minic | |
parent | e3e508c5a33644dd2ffdd10cb7319521d292ca15 (diff) | |
download | compilertests-93815e0c124b4f05043cf6c4c91a3f8cef17f34e.tar.gz compilertests-93815e0c124b4f05043cf6c4c91a3f8cef17f34e.tar.bz2 |
more logical skip_comments with one lookahead without get_char
Diffstat (limited to 'minic')
-rw-r--r-- | minic/scan.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/minic/scan.c b/minic/scan.c index 8b2e290..1e0f358 100644 --- a/minic/scan.c +++ b/minic/scan.c @@ -15,7 +15,7 @@ void scanner_reset( Scanner *s ) { s->peek = ' '; s->row = 1; - s->col = 1; + s->col = 0; s->pos = s->src; } @@ -85,6 +85,8 @@ static void error( Scanner *s, char *msg ) static void skip_comment( Scanner *s ) { + get_char( s ); + get_char( s ); while( s->peek != '*' ) { get_char( s ); } @@ -92,13 +94,16 @@ static void skip_comment( Scanner *s ) if( s->peek != '/' ) { error( s, "unclosed comment" ); } + get_char( s ); } scanner_Symbol scanner_scan( Scanner *s ) { scanner_Symbol sym; + int c; for( ;; ) { + get_char( s ); skip_whitespace( s ); switch( s->peek ) { case '\0': @@ -109,12 +114,11 @@ scanner_Symbol scanner_scan( Scanner *s ) return sym; case '/': - get_char( s ); - if( s->peek == '*' ) { + c = peek_char( s, 1 ); + if( c == '*' ) { if( s->debug ) { print( "SCANNER(COMMENT_START)" ); } - get_char( s ); skip_comment( s ); if( s->debug ) { print( "SCANNER(COMMENT_END)" ); |