I\'m trying to use antlr4 version 4.4 and the python2 runtime. The grammar is from the antlr4 book, page 6, file: Hello.g4:
grammar Hello;
Oddly, toStringTree is a class method in the Python runtimes. You can call it like this to get the lisp style parse tree including stringified tokens:
from antlr4 import *
from antlr4.tree.Trees import Trees
# import your parser & lexer here
# setup your lexer, stream, parser and tree like normal
print(Trees.toStringTree(tree, None, parser))
# the None is an optional rule names list
It looks like you took the wrong toStringStree
function.
Take a look at the java docs.
This explains the error message "object does not support indexing". The function you chose expects a list of rule names and not the parser.