[antlr-interest] unknown parameters
Jim Idle
jimi at temporal-wave.com
Mon Nov 5 09:19:31 PST 2007
You cannot use parameters in predicates I am afraid, as when the predicate
fragment is generated, the rule parameter is no longer in scope. I suspect
that you are using the backtrack=true; option, which is where these options
are coming from. If you wish to pass in such a parameter AND you wish to use
backtrack=true, then you will need to use scopes rather than local
parameters.
Overall it is probably best to get a grammar that does not use
backtrack=true, but using scopes will solve your issue with parameters.
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Corno Schraverus
> Sent: Monday, November 05, 2007 4:55 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] unknown parameters
>
> Hi all,
>
> I ran into a problem with antlr 3, is there anybody that can help me
> with
> that?
> I have a rule with a paramater ('context') and within that rule I call
> another rule with that parameter as an argument (The grammar is an
> adjusted
> version of the java grammar).
> The generated code (in C, see below) contains a function that is a
> fragment
> of the rule, but lacks the parameter, and therefore gives a compile-
> error.
> Is this an error in the code generation or am I doing something wrong?
>
> TIA,
>
> Corno
>
>
> The rule:
> ---------------------------
>
> classBodyDeclarations [Context * context]
> :
> ( ';'
> | ( modifier [context]
> )*
> ( typeParameters [context]
> ( ( type [context]
> | 'void'
> )
> methodDeclaratorRest [context]
> | constructorDeclaratorRest [context]
> )
> | type [context]
> methodDeclaratorRest [context]
> | type [context]
> variableDeclarators [context]
> ';'
> )
> )*
> ;
> --------------------------
>
> The generated code:
> --------------------------
>
> // $ANTLR start synpred11
> static void synpred11_fragment(pJavaParser ctx ) //<-------------
> parameter
> missing here
> {
> // Java.g:68:5: ( type[context] methodDeclaratorRest[context] )
> // Java.g:68:5: type[context] methodDeclaratorRest[context]
> {
> FOLLOWPUSH(FOLLOW_type_in_synpred11207);
> type(ctx, context); //<-------------
> -
> problem is here
> FOLLOWPOP();
> if (HASEXCEPTION())
> {
> goto rulesynpred11Ex;
> }
> if (HASFAILED())
> {
> return ;
> }
> FOLLOWPUSH(FOLLOW_methodDeclaratorRest_in_synpred11214);
> methodDeclaratorRest(ctx, context);
> FOLLOWPOP();
> if (HASEXCEPTION())
> {
> goto rulesynpred11Ex;
> }
> if (HASFAILED())
> {
> return ;
> }
>
> }
> .....
> ----------------------------
More information about the antlr-interest
mailing list