If we mix all the binary operators (+, -, *, /) together, we lost the precedence, and user need to explicitly add () to have multiply executed before plus. The reason we put them together is we want to avoid duplicated code in visitor when building AST, because the operator is the only difference
Currently we have (this is wrong)
term
: literal # TmLiteral
| '-' term # TmNegative
| term BINARY_OP term # TmBinaryOp
// | list # TmList
// | record # TmRecord
| '(' term ')' # TmBrackets
;
BINARY_OP
: '+'
| '-'
| '*'
| '/'
;
If we mix all the binary operators (+, -, *, /) together, we lost the precedence, and user need to explicitly add
()
to have multiply executed before plus. The reason we put them together is we want to avoid duplicated code in visitor when building AST, because the operator is the only differenceCurrently we have (this is wrong)
for
1 + 2 * 3
we havebut we should have