-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAST.py
More file actions
49 lines (39 loc) · 1.17 KB
/
AST.py
File metadata and controls
49 lines (39 loc) · 1.17 KB
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
class ASTNode:
pass
class Number(ASTNode):
def __init__(self, value):
self.value = value
class String(ASTNode):
def __init__(self, value):
self.value = value
class Identifier(ASTNode):
def __init__(self, name):
self.name = name
class BinaryOp(ASTNode):
def __init__(self, left, operator, right):
self.left = left
self.operator = operator
self.right = right
class UnaryOp(ASTNode):
def __init__(self, operator, operand):
self.operator = operator
self.operand = operand
class Assignment(ASTNode):
def __init__(self, name, value):
self.name = name
self.value = value
class PrintStatement(ASTNode):
def __init__(self, arguments):
self.arguments = arguments
class IfStatement(ASTNode):
def __init__(self, condition, if_body, else_body=None):
self.condition = condition
self.if_body = if_body
self.else_body = else_body
class WhileStatement(ASTNode):
def __init__(self, condition, body):
self.condition = condition
self.body = body
class Program(ASTNode):
def __init__(self, statements):
self.statements = statements