[antlr-interest] Syntactic predicate for single alternatives

Gokhan Caglar gcaglar at gmail.com
Wed Jan 11 14:46:58 PST 2006


Hi I'm wondering how I can write a syntactic predicate for a special case.
Here is a very simle grammar:

class SmallParser extends Parser;

program
    :
        (DO THIS)=>
        (statement1)*

        (statement2)?
    ;

statement1
    : DO THIS
    ;

statement2
    : DO THAT
    ;

class SmallLexer extends Lexer;

options {
    caseSensitive=false;
    caseSensitiveLiterals=false;
}

tokens
{
    DO="do";
    THIS="this";
    THAT="that";
}


protected
WS_CHAR
    : ' '
    | '\t'
    | '\f'
    | ( options {generateAmbigWarnings=false;}
        : "\r\n"
        | '\r'
        | '\n'
        )
        { newline(); }
    ;

WS : (WS_CHAR)+
  { _ttype = Token.SKIP; }
 ;

At the program rule I think statement2 is an alternative to statement1 in
the following construct:  (statement1)* statement2

However I get the error:  warning:Syntactic predicate ignored for single
alternative

Thanks,

Gokhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060111/1a954d32/attachment.html


More information about the antlr-interest mailing list