I've recently started working on a PHP project that involves evaluating complex arithmetic expressions. While I'm familiar with basic arithmetic operations, I'm struggling with handling precedence and associativity in more complicated expressions. I was hoping someone could provide some guidance on this matter.
To provide some context, I'm building a calculator application that needs to correctly interpret and evaluate arithmetic expressions entered by the user. This means I need to consider operator precedence (e.g., multiplication before addition) and associativity (e.g., left-to-right for addition and subtraction).
I understand that PHP follows the standard rules of operator precedence (e.g., multiplication and division have higher precedence than addition and subtraction), but I'm not exactly sure how to implement this in my code. Additionally, I'm also unsure how to handle cases where operators have the same precedence, such as multiple multiplication or addition operators in one expression.
I've already done some research and found out that PHP uses the usual mathematical conventions for precedence and associativity, but I'm looking for some practical advice and maybe some code examples to help me get started.
Any help or pointers you can provide would be greatly appreciated. Thanks in advance for your assistance!