Hannes Kinks
hkinks@gmail.com
Tallinn 2016
https://bitbucket.org/hkinks/iag0450-antlr
https://bitbucket.org/hkinks/antlr-tutorial
https://bitbucket.org/hkinks/estcompiler
Bison - LALR
Bottom-up parsing
ANTLR - LL(*)
Top-down parsing
LALR - Look-Ahead Left to Right
LL(k) - Left to right, performing Leftmost derivation, with k tokens of lookahead
https://en.wikipedia.org/wiki/LL_parser
Given context-free grammar
((i+i)+i)
Text for parsing
S=>E
=>(E+E)
=>((E+E)+E)
=>((i+E)+E)
=>((i+i)+E)
=>((i+i)+i)
Derivation process:
k element lookahead
E=>(E+E)
or
E=>i
?
Answer: look next symbol
1. Define grammar in Assign.g4
2. ANTLR tool generates code based on specified grammar
3. Parsing given input
4. Walking the parse tree
ParseTree tree = ... ; // tree is result of parsing MyVisitor v = new MyVisitor(); v.visit(tree);