added MOD operator, converting operands to ints

git-svn-id: svn://anubis/fart/trunk@351 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2010-10-07 14:43:56 +00:00
parent c4d8327665
commit fc33024b28
2 changed files with 5 additions and 5 deletions

View File

@ -74,6 +74,9 @@ NodeRef BinOpNode::evaluate()
case '-':
r = o - t;
break;
case '%':
r = (int) o % (int) t;
break;
default:
cerr << "Error: BinOpNode created with op '" << m_op << "'" << endl;
exit(-3);
@ -162,10 +165,6 @@ NodeRef ForNode::evaluate()
}
}
/* clear out all child nodes so that evaluateChildren() doesn't
* attempt to evaluate them */
m_children.clear();
return eval;
}

View File

@ -119,7 +119,7 @@ refptr<Scope> parser_scope;
%right ASSIGN
%left PLUS MINUS
%left TIMES DIVIDE
%left TIMES DIVIDE MOD
%left UMINUS
%%
@ -587,6 +587,7 @@ vector3: LESS expression COMMA expression COMMA expression GREATER {
expression: term { $$ = $1; }
| expression TIMES term { $$ = new BinOpNode('*', $1, $3); }
| expression DIVIDE term { $$ = new BinOpNode('/', $1, $3); }
| expression MOD term { $$ = new BinOpNode('%', $1, $3); }
| MINUS expression %prec UMINUS {
$$ = new BinOpNode('-', new NumberNode(0.0), $2);
}