mirror of
https://github.com/mudabbir-ahmad/UNI-PROG3-CW2-DYOPL.git
synced 2026-10-07 20:00:20 +00:00
27 lines
784 B
Python
27 lines
784 B
Python
import sys
|
|
from antlr4 import *
|
|
from RobotLangLexer import RobotLangLexer
|
|
from RobotLangParser import RobotLangParser
|
|
from RobotLangVisitorUser import RobotLangVisitorUser
|
|
|
|
def main(argv):
|
|
# Determine if reading from a file or standard input
|
|
if len(argv) == 1:
|
|
inpstream = StdinStream()
|
|
else:
|
|
inpname = argv[1]
|
|
inpstream = FileStream(inpname)
|
|
# Lexer analyses the characters
|
|
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()
|
|
|
|
visitor = RobotLangVisitorUser()
|
|
visitor.visit(tree)
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv) |