[antlr-interest] Unit testing grammar productions and injecting EOF
Kaleb Pederson
kaleb.pederson at gmail.com
Mon Oct 5 13:37:53 PDT 2009
I have a grammar that contains the following production:
objectMember : functionExpression | ID;
The unit tests for the above production, however, sometimes passed and
sometimes failed. After some investigation, I found that the reason
for the failure was that EOF wasn't in the expected follow set, which
makes sense when I'm parsing the whole language.
As a workaround, I changed my production, adding EOF as an optional
terminal as follows:
objectMember : functionExpression EOF? | ID EOF?;
Everything now works but I'm curious if a better solution for testing
individual grammar productions exists. Suggestions or alternatives?
Thanks.
--Kaleb
http://twitter.com/kalebpederson
http://kalebpederson.com
More information about the antlr-interest
mailing list