[antlr-interest] error in RegcognitionException; input refers to wrong class.

Vladimir Florentino megavlad at gmail.com
Fri May 8 07:07:34 PDT 2009


Hi, All

 

My name is Vlad. This is my first post at the mailing list.

 

I'm having an issue. I'm doing something like the following:

 

[code]

function run()

                input  = ANTLRStringStream('10110')

                lexer  = SaranLexer(input)

                tokens = CommonTokenStream(lexer)  

                parser = SaranParser(tokens)

                                

                // Run the parser.

                parser.topRule()

end

[/code]

 

This causes a problem in RegcognitionException, because in the constructor
it does:

 

[code]

self.c                                                                     =
self.input.LA(1)

self.line                                                                =
self.input.getLine()

self.index                                                            =
self.input.index()

self.charPositionInLine                                  =
self.input.getCharPositionInLine()

[/code]

 

The issue is that, at this point, input refers to CommonTokenStream, not
ANTLRStringStream.

 

The exception is raised in the codegen-template function:

dfaState(k, edges, eotPredictsAlt, description, stateNumber, semPredState)
::=

 

Specifically, when throwing the exception:

NoViableAltException("<description>", <decisionNumber>, <stateNumber>,
input)

 

At first, I checked if input was of type CommonTokenStream, and then tried
getTokenSource(), but that returns the Lexer, not ANTLRStringStream, which
is what RecognitionException seems to expect (or one of the other
ANTLR*Stream). Also, Lexer doesn't have a getInput function. 

 

I must be doing something funky. I figured that input would automatically
point to the correct source, and I wouldn't have to add/hack my own code in
the codegen-template function.

 

 

Any advice?

 

Regards,

 

Vlad

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090508/9baa63d6/attachment-0001.html 


More information about the antlr-interest mailing list