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[9] inpstream = FileStream(inpname) # 1. Lexer analyses the characters lexer = RobotLangLexer(inpstream) # 2. Create a stream of tokens tokstream = CommonTokenStream(lexer) # 3. Parser produces the abstract syntax tree parser = RobotLangParser(tokstream) # 4. Start parsing from the top rule ('prog' in your grammar) tree = parser.prog() # Printing the parse tree using Marina's PrettyPrint and toStringTree methods (Not-needed for the assignment) # print(TreesUser.toStringTree(tree, None, parser)) # print(TreesUser.PrettyPrint(tree, None, parser)) visitor = RobotLangVisitorUser("2320390") visitor.visit(tree) if __name__ == '__main__': main(sys.argv)