Start with the grammar G6, repeated here: G6: <exp> ::= <exp> + <mulexp> | <mule
ID: 3569574 • Letter: S
Question
Start with the grammar G6, repeated here:
G6: <exp> ::= <exp> + <mulexp> | <mulexp>
<mulexp> ::= <mulexp> * <rootexp> | <rootexp>
<rootexp> ::= (<exp>) | a | b | c
Modify it in the following ways:
a. Add subtraction and division operators (- and /) with the customary precedence and associativity.
b. Then add left-associative operator % between + and * in precedence.
c. Then add right-associative operator = at lower precedence than any of the other operators.
Explanation / Answer
1.
<exp> ::= <exp> + <mulexp> | <exp> - <mulexp> | <mulexp>
<mulexp> ::= <mulexp> * <rootexp> | <mulexp> / <rootexp> | <rootexp>
<rootexp> ::= (<exp>) | a | b | c
2.
<exp> ::= <exp> + <modexp> | <exp> - <modexp> | <modexp>
<modexp> ::= <exp> % <mulexp> | <mulexp>
<mulexp> ::= <mulexp> * <rootexp> | <mulexp> / <rootexp> | <rootexp>
<rootexp> ::= (<exp>) | a | b | c
3.
<exp> ::= <exp> = <equalop>
<equalop> ::= <equalop> + <modexp> | <equalop> - <modexp> | <modexp>
<modexp> ::= <exp> % <mulexp> | <mulexp>
<mulexp> ::= <mulexp> * <rootexp> | <mulexp> / <rootexp> | <rootexp>
<rootexp> ::= (<exp>) | a | b | c
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.