9. ANTLR namespaces
Antlr4.Runtime
org.antlr.v4.runtime
Contains the most commonly used classes and interfaces, such
as the hierarchies for input streams, character and token
buffers, error handling, token construction, lexing, and parsing
Antlr4.Runtime.Atn
org.antlr.v4.atn
This is used internally for ANTLR’s Adaptive LL(*) lexing and
parsing strategy1
Antlr4.Runtime.Dfa
org.antlr.v4.dfa
Holds all of the DFA2 implementation classes
Antlr4.Runtime.Misc
org.antlr.v4.misc
Holds miscellaneous data structures but also the commonly
used TestRig class
Antlr4.Runtime.Sharpen Holds different helpers for C# target language
Antlr4.Runtime.Tree
org.antlr.v4.tree
This package holds all of the classes and interfaces needed to
implement parser trees
org.antlr.v4.runtime.tree.gui A basic parse tree viewer
1. http://en.wikipedia.org/wiki/Augmented_transition_network
2. http://en.wikipedia.org/wiki/Deterministic_finite_automaton
18. Recovery process
● Each generated method is wrapped by try-catch
block
● reoprtError() - reports ErrorListener about
parsing error
● recover() - consumes tokens until it finds one
present in resynchronization set
19. Resynchronization set
Resynchronization set is the union of rule
reference following sets for all the rules on the
invocation stack
Invocation Stack: [group, expr, atom]
Resynchronization Set: { ‘^’, ‘]’ }
21. Recovering from errors in subrules
Subrule start:
● Parsers attempt single token
deletion
● Parsers don’t attempt single
token insertion
Looping subrule continuation
test:
● Acts inside subrule that is looping
construct (...)+
● Parser tries to stay in the loop after
recovery
● Consumes tokens until it finds a token
consistent with one of following sets:
a) another iteration of the loop
b) what follows the loop
c) the resynchronization set of the
current