diff options
author | Michael Forney <mforney@mforney.org> | 2019-02-24 11:53:26 -0800 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-02-24 12:35:09 -0800 |
commit | af126585dd1af74c5dcceda73e49ac9246c524b2 (patch) | |
tree | d83f28fc2bf4d2b23d0ea302ad877d451b992ded | |
parent | 05a8ff0ee5a003e816519486ae78aa4156dfffb4 (diff) | |
download | cproc-af126585dd1af74c5dcceda73e49ac9246c524b2.tar.xz |
scan: Handle comments
-rw-r--r-- | scan.c | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -233,10 +233,31 @@ stringlit(struct scanner *s) } } +static bool +comment(struct scanner *s) +{ + int last; + + switch (s->chr) { + case '/': /* C++-style comment */ + do nextchar(s); + while (s->chr != '\n'); + return true; + case '*': /* C-style comment */ + nextchar(s); + do last = s->chr, nextchar(s); + while (last != '*' || s->chr != '/'); + nextchar(s); + return true; + default: + return false; + } +} + static int scankind(struct scanner *s) { - int tok; + enum tokenkind tok; struct location loc; again: @@ -275,7 +296,10 @@ again: nextchar(s); return TARROW; case '/': - return op2(s, TDIV, TDIVASSIGN); + tok = op2(s, TDIV, TDIVASSIGN); + if (tok == TDIV && comment(s)) + goto again; + return tok; case '<': return op4(s, TLESS, TLEQ, TSHL, TSHLASSIGN); case '=': |