[antlr-interest] NoViableAltException.expecting ?

Sebastien Boving me at sebastienboving.com
Wed Nov 16 11:02:12 PST 2005


Either we're talking about different information, or i'm not getting why it
isn't readily available to ANTLR at code generation time. Taking the example
of the generated python implementation for rule 'base_operation' in a LL(1)
grammar:

def base_operation(self):

la1 = self.LA(1)
if False:
pass
elif la1 and la1 in [LITERAL_show]:
pass
self.show_operation()
elif la1 and la1 in [LITERAL_no,LITERAL_set]:
pass
self.set_operation()
else:
raise antlr.NoViableAltException(self.LT(1), self.getFilename())

why can't you generate

antlr.NoViableAltException(self.LT(1).self.getFilename(), [LITERAL_show,
LITERAL_no, LITERAL_set])

to be raised instead? ANTLR should be able to build this list as it just
constructed the flow control displayed above the error handling, right?

(this could be implemented differently, for instance referencing a rule id
and providing a looking from rule id to next expected tokens, just trying to
make the point using a list)

thanks.


On 11/16/05, Terence Parr <parrt at cs.usfca.edu> wrote:
>
>
> On Nov 16, 2005, at 12:53 AM, Geir Ove Skjaervik wrote:
>
> > Hello,
> >
> > Not a stupid question at all. I think it is just a ANTLR 2.x
> > weakness that we can just hope will get rectified in an 2.x
> > upgrade. I sure miss a more sensible exception in that case as well.
>
> Hi. The data is not easily available to ANTLR at runtime so I didn't
> include it. That is, the code wasn't convenient at the time. Sorry.
>
> Ter
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051116/2402a168/attachment.html


More information about the antlr-interest mailing list