[antlr-interest] Possible code generation problem with arguments (ANTLR 3.1)
Ian Kaplan
iank at bearcave.com
Fri Aug 15 22:25:25 PDT 2008
I pass an argument down through the grammar. This is an object that
contains a simple symbol table and other book keeping information. As the
parse proceeds objects are added to this container object. The grammar is
shown below. As you can see, I set backtrack to true since this is a
section of the grammar that can't be parsed as I've written the grammar
without back tracking.
ANTLR apparently generates syntactic predicate delegates or something.
These are shown below as well. Note that these methods have no argument,
unlike the syntax that they were generated from. They then attempt to call
the method generated for the syntax production with an argument that doesn't
exist.
Is this a bug in ANTLR or a feature? It should be possible to rewrite the
code so that it doesn't use arguments passed downward, but it will be some
work to get this done. So I would be greatful for any insight before I go
down this path. Thanks for your help,
Ian
patternLink[ PatternContainer patternDef ]
options{
backtrack=true; // Allows parser backtracking
memoize=true;
}
: simpleLink[ patternDef ]
| rangeLinkSet[ patternDef ]
| degreeLinkSet[ patternDef ]
;
Generated Java code:
// $ANTLR start synpred1_GraphQuery
public final void synpred1_GraphQuery_fragment() throws
RecognitionException {
// GraphQuery.g:685:7: ( simpleLink[ patternDef ] )
// GraphQuery.g:685:7: simpleLink[ patternDef ]
{
pushFollow(FOLLOW_simpleLink_in_synpred1_GraphQuery1646);
simpleLink(patternDef);
state._fsp--;
if (state.failed) return ;
}
}
// $ANTLR end synpred1_GraphQuery
// $ANTLR start synpred2_GraphQuery
public final void synpred2_GraphQuery_fragment() throws
RecognitionException {
// GraphQuery.g:686:7: ( rangeLinkSet[ patternDef ] )
// GraphQuery.g:686:7: rangeLinkSet[ patternDef ]
{
pushFollow(FOLLOW_rangeLinkSet_in_synpred2_GraphQuery1655);
rangeLinkSet(patternDef);
state._fsp--;
if (state.failed) return ;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080816/478c3a32/attachment.html
More information about the antlr-interest
mailing list