add remainder operation

This commit is contained in:
Thomas Lindner 2023-01-07 09:56:04 +01:00
parent 56330a54ad
commit 919a9f255b
2 changed files with 3 additions and 1 deletions

View file

@ -150,6 +150,7 @@ std::any EmitVisitor::visitExpr(xlangParser::ExprContext *ctx) {
std::any EmitVisitor::visitTerm(xlangParser::TermContext *ctx) { std::any EmitVisitor::visitTerm(xlangParser::TermContext *ctx) {
OPERATOR(Mul, visitTerm, term(), visitFactor, factor(), "mul"); OPERATOR(Mul, visitTerm, term(), visitFactor, factor(), "mul");
OPERATOR(Div, visitTerm, term(), visitFactor, factor(), "div"); OPERATOR(Div, visitTerm, term(), visitFactor, factor(), "div");
OPERATOR(Rem, visitTerm, term(), visitFactor, factor(), "rem");
visitFactor(ctx->factor()); visitFactor(ctx->factor());
return {}; return {};
} }

View file

@ -30,7 +30,7 @@ boolean : Not boolean
expr : expr (Plus|Minus|BitAnd|BitOr|BitXor|ShiftLeft|ShiftRight) term expr : expr (Plus|Minus|BitAnd|BitOr|BitXor|ShiftLeft|ShiftRight) term
| term | term
; ;
term : term (Mul|Div) factor term : term (Mul|Div|Rem) factor
| factor | factor
; ;
factor : Minus factor factor : Minus factor
@ -81,6 +81,7 @@ ShiftRight : '>>';
BitNot : '~'; BitNot : '~';
Mul : '*'; Mul : '*';
Div : '/'; Div : '/';
Rem : '%';
Comma : ','; Comma : ',';
Semicolon : ';'; Semicolon : ';';