[antlr-interest] new attribute ref syntax
Terence Parr
parrt at cs.usfca.edu
Wed Nov 23 12:44:30 PST 2005
here is the comment on the ActionTranslator related to translated $y,
$x.y, $x::y notation:
/** This class embodies the translation of actions written in the target
* language but containing special references that must be translated
* for reasons of terseness and isolation from underlying
implementation.
*
* There are three forms of interest:
*
* $y return value, parameter, rule or token label, predefined
* rule property, or token or rule reference within the enclosing
* rule's outermost alt. y must be a "local" reference; i.e., it
* must be referring to something defined within the enclosing rule.
*
* r[int i] returns [int j]
* : {$i, $j, $start, $stop, $template, $tree}
* (ids+=ID)+ {$ids.size()} // .size is not used by antlr here
* ;
*
* $x.y if x is enclosing rule, y is a return value, parameter, or
* predefined property. If x is a token label, y is predefined
* property of a token. If x is a rule label, y is a return value
* of the invoked rule or a predefined rule property such as "stop".
* If x is a token referenced in that alt, it behaves like a token
* label. If x is a rule reference in that alt, it behaves like
* a rule label.
*
* r[int i] returns [int j]
* : {$r.i, $r.j, $r.start, $r.stop, $r.template, $r.tree}
* ID {$ID.text} s {$s.start; $s.k}
* ;
* s returns [int k] : ... ;
*
* $x::y the only way to access the attributes within a dynamic scope
* regardless of whether or not you are in the defining rule.
*
* scope Symbols { List names; }
* r
* scope {int i;}
* scope Symbols;
* : {$r::i=3;} s {$Symbols::names;}
* ;
* s : {$r::i; $Symbols::names;}
* ;
*
* This is the new syntax as of 11/23/2005 and should simplify things
a bit
* as all dynamic scope stuff is accessed with a different operator.
Actually
* all it does is make the set of scopes to search for $y a bit
smaller. Oh,
* and I should be able to be more specific with error messages.
*/
Ter
More information about the antlr-interest
mailing list