Exercise 1: A Right-Associative Exponentiation Level — Possible Solution ==================================================================== THE NEW PRECEDENCE LEVEL ------------------------------ def factor(self): # unchanged, calls exponent() now instead of unary() expr = self.exponent() while self.match('STAR', 'SLASH'): ... def exponent(self): expr = self.unary() if self.match('CARET'): right = self.exponent() # RECURSIVE call, not a while loop - makes it right-assoc expr = ('binary', 'CARET', expr, right) return expr The key difference from every other binary level in the chapter's own grammar: exponent() calls itself for the right-hand side (via an `if`, not a `while`), instead of looping at its own level the way term() and factor() do. RESULTS ------------------------------ '2 ^ 3 ^ 2' parses as: (2.0 CARET (3.0 CARET 2.0)) Evaluates to: 512.0 Right-associative (2^(3^2)=2^9=512), not left ((2^3)^2=64): True WHY THIS WORKS AS AN ANSWER ------------------------------ Every other operator in the chapter's own grammar is left-associative, built with a `while` loop that keeps nesting new operations on the LEFT side of the growing tree. Exponentiation is the standard counter-example in real-world grammars (mathematics itself defines it right-associative), and the fix is structural, not a special case bolted on: recursing into the SAME function for the right operand, instead of looping, makes the tree grow rightward instead of leftward. This confirms associativity is a genuine, deliberate choice encoded in how a grammar rule is written, not an automatic consequence of a binary operator existing at all.