Académique Documents
Professionnel Documents
Culture Documents
E ::= E + E | E * E | - E | ( E ) | id
E * E
( E ) id
E + E
id id
© Codruta-Mihaela ISTIN 2015
Derivation order
A CFG by itself does not specify the derivation order, so in
some cases multiple derivations are possible for the same
result. In practice two types of derivations are most used:
Leftmost derivation – the leftmost nonterminal in production
is always chosen first for derivation
E → -E → -(E) → -(E+E) → -(id+E) → -(id+id)
Rightmost derivation – the rightmost nonterminal in production is
always chosen first for derivation
E → -E → -(E) → -(E+E) → -(E+id) → -(id+id)