January 2013
Intermediate to advanced
328 pages
8h 5m
English
Some syntax errors are so common that it’s worth treating them specially. For example, programmers often have the wrong number of parentheses at the end of a function call with nested arguments. To handle these cases specially, all we have to do is add alternatives to match the erroneous but common syntax. The following grammar recognizes function calls with a single argument, possibly with nested parentheses in the argument. Rule fcall has two so-called error alternatives.
| | stat: fcall ';' ; |
| | fcall |
| | : ID '(' expr ')' |
| | | ID '(' expr ')' ')' {notifyErrorListeners("Too many parentheses");} |
| | | ID '(' expr {notifyErrorListeners("Missing closing ')'");} |
| | ; |
| | |
| | expr: |
Read now
Unlock full access