January 2013
Intermediate to advanced
328 pages
8h 5m
English
Most programming languages ignore whitespace and comments in between tokens, which means they can appear anywhere. That presents a problem for a parser since it has to constantly check for optional whitespace and comment tokens. The common solution is to simply have the lexer match those tokens but throw them out, which is what we’ve done so far in this book. For example, our Cymbol grammar from Parsing Cymbol threw out whitespace and comments using the skip lexer command.
| | WS : [ \t\n\r]+ -> skip ; |
| | |
| | SL_COMMENT |
| | : '//' .*? '\n' -> skip |
| | ; |
That works great for many applications, such as compilers, because the comments don’t affect code generation. ...
Read now
Unlock full access