Hi

The generation of the method for the syntactic predicate of a rule with a parameter is missing the parameter in its signature, which leads to a compile error.

Rgds

Francis

Here the CMinus grammar modified with the variable rule having a parameter and conditionned by a syntactic predicate:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
program
scope {
  List globals;
  List functions;
}
@init {
  $program::globals = new ArrayList();
  $program::functions = new ArrayList();
}
    : _declaration[2]_+
-> program(globals={$program::globals},functions={$program::functions})
    ;

declaration[int i]
    : _(variable[i])=>variable[i]_ {$program::globals.add($variable.st);}
    |   f=function {$program::functions.add($f.st);}
    ;


_variable[int i]_
    :   type declarator ';'
        -> {$function.size()>0 && $function::name==null}?
           globalVariable(type={$type.st},name={$declarator.st})
        -> variable(type={$type.st},name={$declarator.st})
    ;


Here the generated code
---------------------------------
    // $ANTLR start synpred1_CMinus
public final void synpred1_CMinus_fragment() throws RecognitionException { // C:\\Users\\FrancisANDRE\\workspace\\zAntlr3\\src\\cminus\\CMinus.g:39:9: ( variable[i] ) // C:\\Users\\FrancisANDRE\\workspace\\zAntlr3\\src\\cminus\\CMinus.g:39:10: variable[i]
        {
        pushFollow(FOLLOW_variable_in_synpred1_CMinus101);
variable(i); _// <== i cannot be resolved to a variable CMinusParser.java /zAntlr3/src/cminus line 1744 Java Problem_


        state._fsp--;
        if (state.failed) return ;

        }

    }
    // $ANTLR end synpred1_CMinus

_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev

Reply via email to