3 ms·
Doing operator precedence in Antlr, which is generating LL(wildcard) parsers: expr: mult ('+' mult)* ; mult: atom ('*' atom)* ; atom: INT | '('
by bad_user 16y ago
Doing operator precedence in Antlr, which is generating LL(wildcard) parsers:
expr: mult ('+' mult)* ;
mult: atom ('*' atom)* ;
atom: INT | '(' expr ')' ;
Not much hackery there, just some look-ahead and recursion.
The grammar itself is context-free and LL(k) and the implementation is trivial once you understand what pushdown automatons are (automata theory, right after finite-state machines).