Similar questions 4 more →
Parsing & Syntax Analysis


Answer & solution
Answer: Unambiguous; / has higher precedence than −, and each operator is parsed left-associatively. (no official key was published)
The grammar separates expression levels: E combines terms with minus, while T combines factors with division. Thus id−id/id parses as id−(id/id), never as (id−id)/id. Division has higher precedence than subtraction.
Both recursive productions are left-recursive, so unparenthesized chains group to the left. For example id−id−id has structure (id−id)−id, and id/id/id has structure (id/id)/id. This is a syntactic associativity convention; it does not claim the arithmetic operators obey an associative law.
For uniqueness, consider an expression outside its matched parentheses. If it has a top-level minus, the root must be E→E−T, split at its last such minus because T cannot contain an unparenthesized minus. If there is no such minus, use E→T. Similarly a top-level slash in a term forces T→T/F split at its last top-level slash, since F cannot contain an unparenthesized slash. At the factor level, either the token is id or the uniquely matched outer parentheses contain an expression, to which the same argument applies. Induction on expression length gives a unique parse. Redundant parentheses are allowed by the grammar, but do not create two parses for the same token string.