-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (22 loc) · 768 Bytes
/
main.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
from antlr4 import ParseTreeWalker
from antlr4 import *
from antlr4.tree import *
from MyGrammarLexer import MyGrammarLexer
from MyGrammarParser import MyGrammarParser
from MyGrammarListener import MyGrammarListener
from MyErrorListener import MyErrorListener
from KeyPrinter import KeyPrinter
if __name__ == '__main__':
input = FileStream("example1")
lexer = MyGrammarLexer(input)
stream = CommonTokenStream(lexer)
parser = MyGrammarParser(stream)
# parser.removeErrorListeners()
# listener = MyErrorListener()
# parser.addErrorListener(listener)
tree = parser.program()
print(tree.toStringTree(recog=parser))
# semantic analisys
walker = ParseTreeWalker()
printer = KeyPrinter()
walker.walk(printer, tree)