Add integer ‘-’, ‘*’ and ‘/’ operators

This commit is contained in:
Eelco Dolstra 2013-08-02 16:03:02 +00:00
parent 5d147e125c
commit 47701677e8
4 changed files with 16 additions and 2 deletions

View file

@ -271,7 +271,8 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
%nonassoc EQ NEQ
%right UPDATE
%left NOT
%left '+'
%left '+' '-'
%left '*' '/'
%right CONCAT
%nonassoc '?'
%nonassoc '~'
@ -322,6 +323,9 @@ expr_op
l->push_back($3);
$$ = new ExprConcatStrings(false, l);
}
| expr_op '-' expr_op { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__sub")), $1), $3); }
| expr_op '*' expr_op { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__mul")), $1), $3); }
| expr_op '/' expr_op { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__div")), $1), $3); }
| expr_op CONCAT expr_op { $$ = new ExprOpConcatLists($1, $3); }
| expr_app
;

View file

@ -1 +1 @@
1843
2170

View file

@ -22,5 +22,11 @@ let {
[ (sum (range 1 50))
(123 + 456)
(0 + -10 + -(-11) + -x)
(10 - 7 - -2)
(10 - (6 - -1))
(10 - 1 + 2)
(3 * 4 * 5)
(56088 / 123 / 2)
(3 + 4 * const 5 0 - 6 / id 2)
];
}

View file

@ -49,4 +49,8 @@ rec {
if comp (head list2) (head list1) then [(head list2)] ++ mergeLists comp list1 (tail list2) else
[(head list1)] ++ mergeLists comp (tail list1) list2;
id = x: x;
const = x: y: x;
}