Professional Documents
Culture Documents
1. Write an unambiguous grammar for the language of balanced parentheses, i.e. the
language that contains (among other) the sequences
a) All sequences of as and bs that contain the same number of as and bs (in any order).
b) All sequences of as and bs that contain strictly more as than bs.
c) All sequences of as and bs that contain a different number of as and bs.
d) All sequences of as and bs that contain twice as many as as bs.
A → −A
A →A − id
A → id
is ambiguous by finding a string that has two different syntax trees. Now make two
different unambiguous grammars for the same language:
Grammar A:
S → aSb
S → aS
S→
Grammar B:
S → aSb
S→T
T → aT
T→
Show the syntax trees using the new grammars for the string you used to prove the
original grammar ambiguous.