PLC Nick Flashcards
(5 cards)
Describe what it means for a grammar to be ambiguous
A grammar is ambiguous if two or more parse trees can be derived for a given string
In the exam, how should you show ambiguity?
Do parse trees, or much easier is to select a part of the grammar and double it, such that it’s not clear what’s first or not. Like selecting the rule E;E, put down (E;E);E, E;(E;E). Make sure to replace E with actual values
In a layered grammar, how do you show binding?
Loosest at the top, Tightest at the bottom
In a grammar, how do you show left/right association?
F::= F;G|G, F is forced to left of ; so ; is left associated. F::= G;F|G, F is forced to right of ; so ; is right associated.
E ::= xD | D | if (E < D)then E | E:=E +E |E;E |(E)
D::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
E ::= if (E<D) then E | F
F ::= F;G | G
G ::= H := E + G | H
H ::= xD | D | (E)