Consider the following grammars:

Grammar 1: <exp> ::= <term> | <exp> ^ <term>
<term> ::= <integer> | ( <exp> )
Grammar 2: <exp> ::= <term> | <term> ^ <exp>
<term> ::= <integer> | ( <exp> )
Grammar 3: <exp> ::= <integer> | <exp> ^ <exp> | ( <exp> )

If ^ represents exponentiation, how many of these grammars force 2^3^2 to evaluate to 512?

1
  1. 0
  2. 1
  3. 2
  4. 3

Which operator associativity (left or right) does ^ need to have for 2^3^2 to evaluate to 512?

How does left- and right-recursion patterns in a production correspond to the associativity of the operator defined by the production?

How does the double-recursion pattern (i.e., simultaneous left- and right-recursion) in a production impact the associativity of the operator defined by the production?

In Grammar 1, the ^ operator is left-associative.

In Grammar 2, the ^ operator is right-associative.

In Grammar 3, the ^ operator is neither left- nor right-associative because of the double-recursion in its second production. This grammar is ambiguous.