[antlr-interest] Possible problem with AntlrV3.g

Foust javafoust at gmail.com
Tue Aug 12 13:00:37 PDT 2008


Gerald Rosenberg  wrote:

>  FWIW, does not seem that the absence of the "$" operator 

> in the rewrite phrase affects the generated code: what 

> is generated still appears correct.

 

Unlike for rule references, the Java code generator uses the exact label
name as the local variable name, so $label, currently expands to just
"label". This is not the case for $TOKEN or $rule.

 

Brent

 

Subject: [antlr-interest] Possible problem with AntlrV3.g

 

In the "rule" rule in AntlrV3.g of the Antlr-3.1b2 distribution, does not
appear as if the "modifier" label gets set and, therefore, is never
re-written to the AST.  

        ( modifier=( 'protected'| 'public' | 'private' | 'fragment' ) )?
should be
        ( (modifier= 'protected'|modifier= 'public' |modifier= 'private'
|modifier= 'fragment' ) )?

and

    -> ^( RULE id {modifier!=null?adaptor.create(modifier):null} ^(ARG
$arg)? ^(RET $rt)?
should (likely) be
    -> ^( RULE id {$modifier!=null?adaptor.create($modifier):null} ^(ARG
$arg)? ^(RET $rt)?

FWIW, does not seem that the absence of the "$" operator in the rewrite
phrase affects the generated code: what is generated still appears correct.


The original rule is:

rule
        scope {
                 String name;
        }
        :DOC_COMMENT?
        ( modifier=( 'protected'| 'public' | 'private' | 'fragment' ) )?
        id {$rule::name = $id.text;}
        '!' ?
        ( arg=ARG_ACTION )?
        ( 'returns' rt=ARG_ACTION  )?
         throwsSpec? optionsSpec? ruleScopeSpec? ruleAction*
        ':' altList ';'
         exceptionGroup?
             -> ^( RULE id {modifier!=null?adaptor.create(modifier):null}
^(ARG $arg)? ^(RET $rt)?
         optionsSpec? ruleScopeSpec? ruleAction*
               altList
               exceptionGroup?
               EOR["EOR"]
             )
        ; 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080812/91f25c7c/attachment.html 


More information about the antlr-interest mailing list