cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit af126585dd1af74c5dcceda73e49ac9246c524b2
parent 05a8ff0ee5a003e816519486ae78aa4156dfffb4
Author: Michael Forney <mforney@mforney.org>
Date:   Sun, 24 Feb 2019 11:53:26 -0800

scan: Handle comments

Diffstat:
Mscan.c | 28++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/scan.c b/scan.c @@ -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 '=':