Files
UNI-PROG3-CW2-DYOPL/Q1/Artefacts/main.py
T

25 lines
707 B
Python

import sys
from antlr4 import *
from RobotLangLexer import RobotLangLexer
from RobotLangParser import RobotLangParser
from RobotLangVisitorUser import RobotLangVisitorUser
def main(argv):
if len(argv) == 1:
inpstream = StdinStream()
else:
inpname = argv[1]
inpstream = FileStream(inpname)
lexer = RobotLangLexer(inpstream)
#Create a stream of tokens
tokstream = CommonTokenStream(lexer)
#Parser produces the abstract syntax tree
parser = RobotLangParser(tokstream)
#Start parsing from the top rule
tree = parser.prog()
#execute script
visitor = RobotLangVisitorUser()
visitor.visit(tree)
if __name__ == '__main__':
main(sys.argv)