Multiplication and division operators.

It is an error to use these on anything but numbers. Maybe later
implementing python/ruby-style ("a" * 100) might be handy.
This commit is contained in:
Stephen Dolan committed 2012-09-10 16:57:17 +01:00
1 parent 6f3abbac62
commit aa3ebdfe9b
4 files changed
+52 -1

No files matched your search

+11
View File
@@ -43,6 +43,7 @@
%left OR
%left AND
%left '+' '-'
%left '*' '/'
%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody
@@ -68,6 +69,8 @@ static block gen_binop(block a, block b, char op) {
switch (op) {
case '+': funcname = "_plus"; break;
case '-': funcname = "_minus"; break;
case '*': funcname = "_multiply"; break;
case '/': funcname = "_divide"; break;
}
assert(funcname);
@@ -157,6 +160,14 @@ Exp '-' Exp {
$$ = gen_binop($1, $3, '-');
} |
Exp '*' Exp {
$$ = gen_binop($1, $3, '*');
} |
Exp '/' Exp {
$$ = gen_binop($1, $3, '/');
} |
Term {
$$ = $1;
}