-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatements.py
More file actions
50 lines (35 loc) · 1.01 KB
/
statements.py
File metadata and controls
50 lines (35 loc) · 1.01 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
# coding: utf8
class WriteStatement(object):
"""
This class represents the while statement in the
abstract syntax tree
"""
def __init__(self, op):
# the expression that will be written to standard output
self.operand = op
class ReadStatement(object):
"""
This class represents the read statement, which is
reading one integer from standard input
"""
def __init__(self, op):
self.operand = op
class IfStatement(object):
def __init__(self, cond):
self.condition = cond
self.then = []
def add_to_if(self, stmt):
self.then.append(stmt)
class WhileStatement(object):
def __init__(self, cond):
self.condition = cond
self.statements = []
def add(self, stmt):
self.statements.append(stmt)
class Assignment(object):
def __init__(self, to, what):
self.lhs = to
self.rhs = what
class CallStatement(object):
def __init__(self, expression):
self.call = expression