Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

[antlr] Precedence of arithmetic operators #19

Closed
at15 opened this issue Nov 24, 2017 · 0 comments
Closed

[antlr] Precedence of arithmetic operators #19

at15 opened this issue Nov 24, 2017 · 0 comments
Assignees
Milestone

Comments

@at15
Copy link
Owner

at15 commented Nov 24, 2017

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
    : '+'
    | '-'
    | '*'
    | '/'
    ;

for 1 + 2 * 3 we have

     *
  +   3
1  2

but we should have

   +
1   *
   2  3
@at15 at15 added this to the 0.1 milestone Nov 24, 2017
@at15 at15 self-assigned this Nov 24, 2017
at15 added a commit that referenced this issue Nov 24, 2017
- Fix #18
- can't put it in lexer, it would broke 1 - 2
- found #19, need to handle operator precedence and be dry
at15 added a commit that referenced this issue Nov 24, 2017
- #19 should be solved, didn't write unit test for that, might test it
end to end after a bare bone of REPL is finished (ASTBuilder, TypeChecker, Evaluator)
- add empty type package for Type class and Checker, ast package is only for AST
@at15 at15 closed this as completed in 306fe1e Nov 25, 2017
at15 added a commit that referenced this issue Nov 25, 2017
- test verified #18 #19 #22 are solved, see negative_precedence.rka
- add more exception classes, ReikaException is for checked exception
  - InvalidSyntax for parser error
@at15 at15 added the antlr label Dec 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant