forked from pragdave/nathan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast_builder.py
35 lines (28 loc) · 1.19 KB
/
ast_builder.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
from arpeggio import PTNodeVisitor
from ast_nodes import *
class ASTBuilder(PTNodeVisitor):
def visit_robolang(self, node, children):
#Since the only time that this is being visited by itself is at the beginning of the program
#default count is 1, for "run the program once"
return BlockNode(1, children)
def visit_command(self, node, children):
#R / L / F by themselves
if len(children) == 1:
return CommandNode(1, children[0])
#count + R / count + L / count + F
elif len(children) == 2:
return CommandNode(children[0], children[1])
#block [RF] (with or without count)
else:
if(children[0] == "["):
#count is default of 1, as it is not specified
return BlockNode(1, children[1])
else:
#count is specified as child[0]
return BlockNode(children[0], children[2])
def visit_motion(self, mode, children):
return ForwardNode()
def visit_turn(self, node, children):
return TurnNode(children[0])
def visit_objectmanip(self, node, children):
return ObjManipNode(children[0])