Consider the following grammar for arithmetic expression using binary…

PYQ GATE 1991Modified — slightly modified from the official paper; see the solution

Consider the following grammar for arithmetic expression using binary operators – and/which are not associative:

E → E − T | T

T → T / F | F

F → (E) | id

(E is the start symbol)

(a) Is this grammar unambiguous? If so, what is the relative precedence between – and/if not, give an unambiguous grammar that gives/precedence over -

(b) Does the grammar allow expressions with redundant parentheses as in (id/id) or in id-(id/id)? If so, convert it to a context-aware grammar that generates only minimal-parentheses expressions. You may add one guarded production rule; a parenthesis pair is redundant exactly when deleting it leaves the parse tree unchanged.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…