-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.py
115 lines (101 loc) · 2.99 KB
/
expr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from myToken import myToken
class Expr():
def accept(self, visitor):
pass
class Visitor(Expr):
def visitBinaryExpr(self, binary):
pass
def visitGroupingExpr(self, grouping):
pass
def visitLiteralExpr(self, literal):
pass
def visitUnaryExpr(self, unary):
pass
def visitVariableExpr(self, variable):
pass
def visitAssignExpr(self, assign):
pass
def visitLogicalExpr(self, logical):
pass
def visitCallExpr(self, call):
pass
def visitGetExpr(self, get):
pass
def visitSetExpr(self, set):
pass
def visitThisExpr(self, this):
pass
def visitSuperExpr(self, super):
pass
class Binary(Expr):
def __init__(self, left: Expr, operator: myToken, right: Expr):
self.left = left
self.operator = operator
self.right = right
def accept(self, visitor: Visitor):
return visitor.visitBinaryExpr(self)
class Grouping(Expr):
def __init__(self, expression: Expr):
self.expression = expression
def accept(self, visitor: Visitor):
return visitor.visitGroupingExpr(self)
class Literal(Expr):
def __init__(self, value):
self.value = value
def accept(self, visitor: Visitor):
return visitor.visitLiteralExpr(self)
class Unary(Expr):
def __init__(self, operator: myToken, right: Expr):
self.operator = operator
self.right = right
def accept(self, visitor: Visitor):
return visitor.visitUnaryExpr(self)
class Variable(Expr):
def __init__(self, name):
self.name=name
def accept(self, visitor):
return visitor.visitVariableExpr(self)
class Assign(Expr):
def __init__(self, name, value):
self.name=name
self.value=value
def accept(self, visitor):
return visitor.visitAssignExpr(self)
class Logical(Expr):
def __init__(self, left, operator, right):
self.left=left
self.operator=operator
self.right=right
def accept(self, visitor):
return visitor.visitLogicalExpr(self)
class Call(Expr):
def __init__(self, callee, paren, arguments):
self.callee=callee
self.paren=paren
self.arguments=arguments
def accept(self, visitor):
return visitor.visitCallExpr(self)
class Get(Expr):
def __init__(self, obj, name):
self.obj=obj
self.name=name
def accept(self, visitor):
return visitor.visitGetExpr(self)
class Set(Expr):
def __init__(self, obj, name, value):
self.obj=obj
self.name=name
self.value=value
def accept(self, visitor):
return visitor.visitSetExpr(self)
class This(Expr):
def __init__(self, keyword):
self.keyword=keyword
def accept(self, visitor):
return visitor.visitThisExpr(self)
class Super(Expr):
def __init__(self, keyword, method):
self.keyword=keyword
self.method=method
def accept(self, visitor):
return visitor.visitSuperExpr(self)