-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (36 loc) · 894 Bytes
/
Copy pathmain.py
File metadata and controls
48 lines (36 loc) · 894 Bytes
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
from lexer import Lexer
from my_parser import Parser
text_input = """
INITIATING COUNTDOWN SEQUENCE
engine_specific_impulse is 150
StageBlueprint command_module:
specificImpulse is engine_specific_impulse
wetMass is 1000
dryMass is 500
engines is 1
BuildStage
Program launch requires stage
beginBurn for 120 seconds stage
flightStatusReport stage.wetMass > stage.dryMass
confirm
houstonWeReadYou
Shutdown
EndProgram
initiate launch command_module
WE HAVE LIFTOFF
"""
lexer = Lexer().get_lexer()
tokens = lexer.lex(text_input)
pg = Parser()
pg.parse()
parser = pg.get_parser()
def token_generator(token_list):
for token in token_list:
print(token)
yield token
try:
result = parser.parse(tokens)
print("Parsing successful!")
except Exception as e:
print("Parsing failed:")
print("Exception:", e)