compiler

lexical analysis

follow

first
nullity
regex to DFA

parser

arithmetic expressions
example
look like this
Derivation

context free grammar
The language defined by a context-free grammar
ambiguous grammar
give int + int * int
left derivation
right derivation

Non-ambiguous grammar
give int + int * int * int

bottom-up parsing
- scan the input from left to right
- look for right-hand sides of production rules to build the derivation tree from bottom to top

LR parsing (Knuth, 1965)
Using an automaton and considering the first k tokens of the input;
this is called LR(k) analysis (LR means “Left to right scanning, Rightmost derivation”)

LR table

example

Construction of the automation and the table
NULL
Let .
holds if and only if we can derive from , i.e.,
FIRST
Let .
is the set of all terminals starting words derived from , i.e.,
FOLLOW
Let .
is the set of all terminals that may appear after in a derivation, i.e.,
