You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following Python3 code and custom grammar Separated:
importsys;
fromantlr4import*fromSeparatedLexerimportSeparatedLexerfromSeparatedParserimportSeparatedParserdefmain(argv):
code=open('Text', 'r').read()
codeStream=InputStream(code)
lexer=SeparatedLexer(codeStream)
tokens=lexer.getAllTokens()
tokensSource=ListTokenSource.ListTokenSource(tokens)
tokensStream=CommonTokenStream(tokensSource)
#tokensStream = CommonTokenStream(lexer) # use this statement to overcome the bugparser=SeparatedParser(tokensStream)
tree=parser.rule1()
print("Tree ", tree.toStringTree(recog=parser));
if__name__=='__main__':
main(sys.argv)
It's not working properly. The following error occurs:
Error
Traceback (most recent call last):
File "main.py", line 20, in <module>
main(sys.argv)
File "main.py", line 16, in main
tree = parser.rule1()
File "SeparatedParser.py", line 122, i
n rule1
localctx.t1 = self.a()
File "SeparatedParser.py", line 326, i
n a
self.match(SeparatedParser.A)
File "Parser.py", line 113, in match
self.consume()
File "Parser.py", line 329, in consume
self.getInputStream().consume()
File "BufferedTokenStream.py", line 99, in consume
if self.sync(self.index + 1):
File "BufferedTokenStream.py", line 111, in sync
fetched = self.fetch(n)
File "BufferedTokenStream.py", line 123, in fetch
t = self.tokenSource.nextToken()
File "ListTokenSource.py", line 81, in nextToken
previousStop = self.tokens[len(self.tokens) - 1].stopIndex
AttributeError: 'CommonToken' object has no attribute 'stopIndex'
Python code
Consider the following Python3 code and custom grammar
Separated
:It's not working properly. The following error occurs:
Error
Java
Meanwhile the Java code works good:
So, I am not able to parse the custom tokens list.
The text was updated successfully, but these errors were encountered: