Consider the grammar G1 that is shown below: G1: * ::= + | ::= *

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Consider the grammar G1 that is shown below: G1: * ::= + | ::= *

Post 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply