Page 1 of 1

Consider the grammar G1 that is shown below: G1: * ::= + | ::= *
Posted: Mon Jun 06, 2022 4:37 pm
by answerhappygod
Consider the grammar G1 that is shown below:
G1: <exp>* ::= <exp> + <mulexp>
| <mulexp>
<mulexp> ::=
<mulexp> * <rootexp> | <rootexp>
<rootexp> ::= ( <exp>
)
|
a | b | c
(3 points) Modify the above grammar by adding the
subtraction operator (-) with the customary precedence and
associativity to the grammar.
(2 points) Show that your extended grammar can derive
the following sentences:
a+b-c
a-b+c
3. (3 points) Modify the above grammar by adding the
division operators (/) with the customary precedence and
associativity to the grammar.
4. (2 points) Show that your extended grammar can derive
the following sentences:
a*b/c
a/b*c
5. (3 points) Modify the above grammar by adding the
equality operator (==) with the lowest precedence of all operators
in the grammar and is left associative.
6. (2 points) Show that your extended grammar can derive
the following sentences:
a+b == b
a == b == c
7. (5 points) With the modifications you made to this
grammar, is this grammar G1 ambiguous? Why or why not?
Consider the grammar G2 that is shown
below:
G2: <pet> ::= <mammal> |
<reptile>
<mammal> ::= cat | dog |
<empty>
<reptile> ::= turtle | snake |
<empty>
Using the grammar given above, answer the following
questions:
8. (5 points) Show that the above grammar is
ambiguous.
9. (5 points) Give an unambiguous grammar for the same
language generated by the grammar above.