Using these steps I'm trying to generate the parse tree for Antlr4 Python3.g4 grammar file, to parse python3 code, I've generated my python parser using ANTLR. But I'm unsure how to pass in a python file as the InputStream doesn't accept this.
I've currently managed to pass it in as a text file:
def main():
with open('testingText.txt') as file:
data = file.read()
input_stream = InputStream(data)
lexer = Python3Lexer(input_stream)
stream = CommonTokenStream(lexer)
parser = Python3Parser(stream)
tree = parser.single_input()
print(tree.toStringTree(recog=parser))
But I get errors to do with 'mismatched input <EOF>' and sometimes 'no viable alternative as input <EOF>'
I would like to pass in a .py file, and I'm not sure what to do about the <EOF> issues