Last active
June 1, 2018 10:55
-
-
Save jsharf/8cbf50621e922b1b41fb1011ec844487 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A _ B, where _ = +, -, *, /, AND, OR, =, ... | |
class Binop { | |
public: | |
enum Operation { | |
ADD = 0, | |
SUBTRACT = 1, | |
MUL = 2, | |
DIV = 3, | |
AND = 4, | |
OR = 5, | |
}; | |
Binop(Node *lhs, Node *rhs, Operation optype) | |
: lhs_(lhs), rhs_(rhs), optype_(optype) {} | |
Binop(Node *lhs, Node *rhs, Operation optype) { | |
lhs_ = lhs; | |
rhs_ = rhs; | |
optype_ = optype; | |
} | |
std::string GetType() const { | |
if (optype_ == ADD) { | |
return "+"; | |
} | |
if (optype_ == SUB) | |
} | |
private: | |
Node *lhs_, *rhs_; | |
Operation optype_; | |
}; | |
AbstractSyntaxTree tree = Parse(code); | |
for (Node n : tree) { | |
if (n.IsArray()) { | |
makeArray(n.....); | |
} else { | |
printID(n.name(), n.id(), n.type()); | |
} | |
} | |
// NO | |
BinOp myoperation; | |
return BinOp(blah) | |
Binop is a pure virtual class. This is the same thing as an abstract class in Java | |
// Yes | |
Add myaddition(variable, 3); | |
return Add(expr1, expr2); | |
Mul slfdkjsldkfj(var, 3); | |
Mul *mul = new Mul(var, 3); | |
function processBinop(BinOp *op) { | |
std::cout << op->getOp(); | |
} | |
processBinop(&slfdkjsldkfj); | |
processBinop(mul); | |
processBinop(&myaddition); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment