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)