diff options
Diffstat (limited to 'src/infix_calc_parser.yy')
-rw-r--r-- | src/infix_calc_parser.yy | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/infix_calc_parser.yy b/src/infix_calc_parser.yy index 6b61fcf..4e5103b 100644 --- a/src/infix_calc_parser.yy +++ b/src/infix_calc_parser.yy @@ -72,13 +72,13 @@ %token <std::string> ERROR
%nterm <double> real_number
-%nterm <rpn_token_t> unary_func
+%nterm <rpn_calc::rpn_token_t> unary_func
%token LPAREN RPAREN EOL
%left SUB ADD
-%left MUL DIV
-%left SIN COS TAN ARCSIN ARCCOS ARCTAN
+%left MUL DIV MOD
+%left ABS SIN COS TAN ARCSIN ARCCOS ARCTAN
%left POW LOG LOG10 EXP
%left SQRT
%left NEG
@@ -86,37 +86,39 @@ %%
expression : product
- | expression ADD product { cc.put_rpn(rpn_token_t::ADD); }
- | expression SUB product { cc.put_rpn(rpn_token_t::SUB); }
+ | expression ADD product { cc.put_rpn(rpn_calc::rpn_token_t::ADD); }
+ | expression SUB product { cc.put_rpn(rpn_calc::rpn_token_t::SUB); }
;
product : operand
- | product MUL operand { cc.put_rpn(rpn_token_t::MUL); }
- | product DIV operand { cc.put_rpn(rpn_token_t::DIV); }
- | product POW operand { cc.put_rpn(rpn_token_t::POW); }
+ | product MUL operand { cc.put_rpn(rpn_calc::rpn_token_t::MUL); }
+ | product DIV operand { cc.put_rpn(rpn_calc::rpn_token_t::DIV); }
+ | product MOD operand { cc.put_rpn(rpn_calc::rpn_token_t::MOD); }
+ | product POW operand { cc.put_rpn(rpn_calc::rpn_token_t::POW); }
;
operand : IDENTIFIER { cc.put_rpn(std::move($1)); }
| ADD IDENTIFIER { cc.put_rpn(std::move($2)); }
| SUB IDENTIFIER { cc.put_rpn(std::move($2));
- cc.put_rpn(rpn_token_t::NEG);
+ cc.put_rpn(rpn_calc::rpn_token_t::NEG);
}
| LPAREN expression RPAREN
| unary_func LPAREN expression RPAREN { cc.put_rpn($1); }
| real_number { cc.put_rpn($1); }
;
-unary_func : SIN { $$=rpn_token_t::SIN; } |
- COS { $$=rpn_token_t::COS; } |
- TAN { $$=rpn_token_t::TAN; } |
- ARCSIN { $$=rpn_token_t::ARCSIN; } |
- ARCCOS { $$=rpn_token_t::ARCCOS; } |
- ARCTAN { $$=rpn_token_t::ARCTAN; } |
- LOG { $$=rpn_token_t::LOG; } |
- LOG10 { $$=rpn_token_t::LOG10; } |
- EXP { $$=rpn_token_t::EXP; } |
- SQRT { $$=rpn_token_t::SQRT; } |
- NEG { $$=rpn_token_t::NEG; } ;
+unary_func : ABS { $$=rpn_calc::rpn_token_t::ABS; } |
+ SIN { $$=rpn_calc::rpn_token_t::SIN; } |
+ COS { $$=rpn_calc::rpn_token_t::COS; } |
+ TAN { $$=rpn_calc::rpn_token_t::TAN; } |
+ ARCSIN { $$=rpn_calc::rpn_token_t::ARCSIN; } |
+ ARCCOS { $$=rpn_calc::rpn_token_t::ARCCOS; } |
+ ARCTAN { $$=rpn_calc::rpn_token_t::ARCTAN; } |
+ LOG { $$=rpn_calc::rpn_token_t::LOG; } |
+ LOG10 { $$=rpn_calc::rpn_token_t::LOG10; } |
+ EXP { $$=rpn_calc::rpn_token_t::EXP; } |
+ SQRT { $$=rpn_calc::rpn_token_t::SQRT; } |
+ NEG { $$=rpn_calc::rpn_token_t::NEG; } ;
real_number : UREAL { $$=$1; } |
ADD UREAL { $$=$2; } |
|