[antlr-interest] Default values in tree rewrite rules

Emond Papegaaij e.papegaaij at student.utwente.nl
Fri Aug 11 14:11:15 PDT 2006


On Friday 11 August 2006 18:53, you wrote:
> Emond Papegaaij asked:
> >I've got the following parser rule in which 'superclass' is optional:
> >  nodeDecl
> >
> >   : (options {k = 1;} : (nodeNames ':')=> bindings=nodeNames ':')?
> >
> >     (declAbstract=ABSTRACT)?
> >     type=targetClass
> >     ('extends' superclass=targetClass)?
> >     ( CBR_OPEN body CBR_CLOSE | SEMI )
> >     -> ^(NODE_SPEC $type $declAbstract? $superclass? body? $bindings?)
> >   ;
> >
> >Now I want superclass to become the tree ^(TYPE["Node"]) when it is not
> >defined in the input (and it will no longer be optional in the rewrite
> >rule).
> indeed. does this work? 
>
> nodeDecl
>    : (options {k = 1;} : (nodeNames ':')=> bindings=nodeNames ':')?
>      (declAbstract=ABSTRACT)?
>      type=targetClass
>      sc=superClass
>      ( CBR_OPEN body CBR_CLOSE | SEMI )
>      -> ^(NODE_SPEC $type $declAbstract? $sc body? $bindings?)
>    ;
>
> superClass :
>      ( /* empty */ -> ^(TYPE["Node"]) )
>    | ( ('extends' targetClass) -> targetClass )
> ;
>
Thanks, that seems to be what I'm looking for.

Best regards,
Emond


More information about the antlr-interest mailing list