File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,11 +6,9 @@ public class ParserExample {
66
77 void parsePrint () throws Exception {
88 m_lexer .expect (com .compiler .TokenIntf .Type .PRINT );
9- m_lexer .expect (com .compiler .TokenIntf .Type .WHITESPACE );
109 com .compiler .Token number = m_lexer .lookAhead ();
1110 m_lexer .expect (com .compiler .TokenIntf .Type .INTEGER );
1211 m_lexer .expect (com .compiler .TokenIntf .Type .SEMICOLON );
13- m_lexer .expect (com .compiler .TokenIntf .Type .WHITESPACE );
1412 System .out .println (number .m_value );
1513 }
1614
@@ -32,8 +30,7 @@ public static void main(String[] args) throws Exception {
3230 parser .parse ("""
3331 PRINT 1;
3432 PRINT 2;
35- PRINT 3;
36- """ );
33+ PRINT 3;""" );
3734 }
3835
3936}
Original file line number Diff line number Diff line change @@ -190,7 +190,13 @@ public Token lookAhead() {
190190 }
191191
192192 public void advance () throws Exception {
193- m_currentToken = nextToken ();
193+ Token token = nextToken ();
194+ while (token .m_type == Token .Type .WHITESPACE ||
195+ token .m_type == Token .Type .MULTILINECOMMENT ||
196+ token .m_type == Token .Type .LINECOMMENT ) {
197+ token = nextToken ();
198+ }
199+ m_currentToken = token ;
194200 }
195201
196202 public void expect (Token .Type tokenType ) throws Exception {
You can’t perform that action at this time.
0 commit comments