title: How does a simple calculator with parentheses work?
body: <p>I want to learn how calculators work. For example, say we have inputs in infix notation like this:</p>
  
  <p>1 + 2 x 10 - 2</p>
  
  <p>The parser would have to respect common rules in math. In the above example this means:</p>
  
  <p>1 + (2 x 10) - 2 = 19 (rather than 3 x 10 - 2 = 28)</p>
  
  <p>And then consider this:</p>
  
  <p>1 + 2 x ((2 / 9) + 7) - 2</p>
  
  <p>Does it involve an Abstract Syntax Tree? A binary tree? How is the order of operations ensured to be mathematically correct? Must I use the shunting-yard algorithm to convert this to postfix notation? And then, how would I parse it in postfix notation? Why convert in the first place?</p>
  
  <p>Is there a tutorial which shows how these relatively simple calculators are built? Or can someone explain?</p>