At 4:10 in the video, the AST for 50+20+30 appears to be 50+(20+30). However, t...

David Troendle Answered 1 answer
Question by David Troendle 2 years ago

Question

At 4:10 in the video, the AST for 50+20+30 appears to be 50+(20+30). However, the associativity of + is left to right. Should it be (50+20)+30, which is a slightly different AST?

Answers

Answered by Daniel McCarthy

Instructor

Thank you for pointing that out. It's true that the addition operator (+) is left-associative, which means operations are grouped from left to right. However, since addition is commutative and associative, both 50 + (20 + 30) and (50 + 20) + 30 result in the same sum. Later in the course we respect mathematical order by reordering our AST to ensure multiplication takes predecence and other mathemtical rules are followed