diff --git a/pj1-go/lexer.go b/pj1-go/lexer.go index 89ba5b7..97cd3df 100644 --- a/pj1-go/lexer.go +++ b/pj1-go/lexer.go @@ -183,6 +183,28 @@ func (l *Lexer) scanToken() { for l.peek() != '\n' && !l.atEnd() { l.advance() } + } else if l.match('*') { + l.advance() + l.advance() // swallow the "/*" + nesting := 1 + // A comment goes until we reach */, however, + // the comments can also nest + for { + if l.peek() == '/' && l.peekNext() == '*' { + nesting++ + l.advance() + l.advance() + } else if l.peek() == '*' && l.peekNext() == '/' { + nesting-- + l.advance() + l.advance() + } else { + if l.peek() == '\n' { + l.line++ + } + l.advance() + } + } } else if l.match('.') { l.addSimpleToken(SLASH_DOT) } else if l.match('_') {