[antlr-interest] Block Returning Value in ANTLR

Bryan Ewbank ewbank at gmail.com
Fri Apr 1 06:53:49 PST 2005


There's several ways to specify a default for xy:

    /**
     * initialize in declaration
     */
    range_opt returns [pair<int,int> xy = ... ]
    :
        ( xy=range )?
    ;


    /**
     * initialize in preamble
     */
    range_opt returns [pair<int,int> xy]
    { xy = ... ; }
    :
        ( xy=range ) ?
    ;

    /**
     * initialize in alternative - note that
     * the ()? is replaced with ( | )
     */
    range_opt returns [pair<int,int> xy]
    :
        ( /* nothing here */
            { xy = ...; }
        | xy=range
        )
    ;

On Apr 1, 2005 9:08 AM, Shalini Sharma <shalini.sh at gmail.com> wrote:
> range_opt returns [pair<int,int> xy] : (xy=range)? ;
> 
> i want to specify xy= some deafult value in case range is empty


More information about the antlr-interest mailing list