1 /* Copyright (C) 2008, Kristian Rumberg (kristianrumberg@gmail.com)
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "BinExpr.hpp"
20 BinExpr::BinExpr(Expr
* a1
, Expr
* a2
): m_a1(a1
), m_a2(a2
) {}
21 AddExpr::AddExpr(Expr
* n1
, Expr
* n2
) : BinExpr(n1
, n2
) {}
22 SubExpr::SubExpr(Expr
* n1
, Expr
* n2
) : BinExpr(n1
, n2
) {}
23 MulExpr::MulExpr(Expr
* n1
, Expr
* n2
) : BinExpr(n1
, n2
) {}
24 DivExpr::DivExpr(Expr
* n1
, Expr
* n2
) : BinExpr(n1
, n2
) {}
26 Number
AddExpr::eval() const
28 return left()->eval() + right()->eval();
31 Number
SubExpr::eval() const
33 return left()->eval() - right()->eval();
36 Number
MulExpr::eval() const
38 return left()->eval() * right()->eval();
41 Number
DivExpr::eval() const
43 return left()->eval() / right()->eval();