Created
May 11, 2022 15:08
-
-
Save gernst/d88f474dc4ac293b0c924a3d7ad59d70 to your computer and use it in GitHub Desktop.
This file contains 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
class Expr: | |
def eval(self, state): | |
pass | |
class Var(Expr): | |
def __init__(self, name): | |
self.name = name | |
def eval(self, state): | |
return state[name] | |
class BinOp(Expr): | |
def __init__(self, op, left, right): | |
self.op = op # here: a binary lambda function, but can be anything | |
self.left = left | |
self.right = right | |
def eval(self, state): | |
return op(left.eval(state), right.eval(state)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment