hawkw / decaf

like Java, but less so
hawkweisman.me/decaf
Other
18 stars 4 forks source link

Fix order of operations for arithmetic operators #11

Closed hawkw closed 9 years ago

hawkw commented 9 years ago

It makes this:

 12         AssignExpr:
 12            FieldAccess:
 12               Identifier: d
 12            Operator: =
 12            ArithmeticExpr:
 12               IntConstant: 2
 12               Operator: +
 12               ArithmeticExpr:
 12                  IntConstant: 3
 12                  Operator: *
 12                  ArithmeticExpr:
 12                     IntConstant: 4
 12                     Operator: -
 12                     ArithmeticExpr:
 12                        IntConstant: 6
 12                        Operator: /
 12                        IntConstant: 2

when it should make this:

 12         AssignExpr:
 12            FieldAccess:
 12               Identifier: d
 12            Operator: =
 12            ArithmeticExpr:
 12               ArithmeticExpr:
 12                  IntConstant: 2
 12                  Operator: +
 12                  ArithmeticExpr:
 12                     IntConstant: 3
 12                     Operator: *
 12                     IntConstant: 4
 12               Operator: -
 12               ArithmeticExpr:
 12                  IntConstant: 6
 12                  Operator: /
 12                  IntConstant: 2
hawkw commented 9 years ago

PEMDAS, Max. PEMDAS.

hawkw commented 9 years ago

My commits 9ad843b and a3a073a fix this.