Parsing & Syntax Analysis


Answer & solution
Answer: Yes. E→T|S; S→E−T|E−(S); T→id|T/F|(S)/F; F→id|(S)|(T/F)|((S)/F). Only the production group S is added. (no official key was published)
The original grammar allows both examples through F→(E). Deleting parentheses must be judged by preservation of the parse tree under / precedence and left associativity, not accidental numerical identities for particular values. Parentheses are needed around a subtraction in either operand of division, around a division in the right operand of division, and around a subtraction in the right operand of subtraction. They are not needed around a whole expression, a single id, a left operand at equal precedence, or a division used as a subtraction operand.
Use the following four-nonterminal grammar:
E→T | S
S→E−T | E−(S)
T→id | T/F | (S)/F
F→id | (S) | (T/F) | ((S)/F)
S is exactly subtraction-rooted, while T/F and (S)/F together are exactly division-rooted. This grammar generates every binary expression tree with no removable parenthesis pair. F appears only after /, preventing redundant outer parentheses. Examples: it generates id−(id−(id−id)) and id/((id−id)/id), but rejects (id/id), id−(id/id), (id), and ((id−id))/id. The source’s “one more production rule” is interpreted in the common sense of one more nonterminal production group: only S is added to E,T,F. All three original groups must change to prevent the old whole-expression wrapping while preserving needed contexts. A global minimum in number of RHS alternatives is not claimed because the source does not define its edit metric.