I am trying to use lexer.py and parser.py in python , but it has error in this code :
import antlr3
import antlr3.tree
import traceback
from test22Lexer import test22Lexer
from test22Parser import test22Parser
char_stream = antlr3.ANTLRStringStream("input.txt")
lexer = test22Lexer(char_stream)
tokens = antlr3.CommonTokenStream(lexer)
parser = test22Parser(tokens)
parser.block()
and the error is :
class block_return(ParserRuleReturnScope):
NameError: name 'ParserRuleReturnScope' is not defined
I need help :D
parser :
class block_return(ParserRuleReturnScope):
def __init__(self):
super(test22Parser.block_return, self).__init__()
self.tree = None
I just had the exact same problem. I went through the egg looking for the class (ParserRuleReturnScope), and it did not appear to exist. This was using version 3.0.1. I was then able to find the 3.1.3 runtime, and the associated version of the ANTLR generator JAR file. Once I generated using 3.1.3, the problem went away. So, I would recommend installing 3.1.3, here are the relevant links I used:
ANTLR generator: https://github.com/antlr/website-antlr3/blob/gh-pages/download/antlr-3.1.3.jar
Download the .jar file, and then run: java -jar path/to/jar/file myGrammar.g
Once your parser/lexer are generated using 3.1.3, use the same version runtime: https://github.com/antlr/website-antlr3/blob/gh-pages/download/Python/antlr_python_runtime-3.1.3-py2.5.egg
You can install that, e.g. with easy_install.
Now the module loads (syntax is correct), but I'm still working through runtime errors. Progress!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With