[antlr-interest] Who can tell me what's the mean of # in the .gfile of parser?
Bryan Ewbank
ewbank at gmail.com
Wed Oct 25 03:25:03 PDT 2006
I can only speak for C++ here... have yet to use Java...
The [] are used to pass additional arguments to a production -- formally, to
pass inherited attributes. They require the production to be declared with
additional inputs. The current AST node is always the first argument to the
function in the generated C++ code, those you provide are added as additional
arguments.
relExpr : typeSpec[true] ;
// when matching a relExpr, attempt to match a typeSpec using the value
// "true" as an inherited attribute
Note that synthesized attributes (those passed up the tree) can be passed this
way as well...
relExpr
{ int x = 0; }
: myExpr[&x]
{ ... x ... }
;
// the address of "x" is passed to myExpr, and we assume that myExpr will
// change the value of x in some way before passing control back to the
// relExpr production.
On 10/24/06, Yu Tao <yutao at td-tech.com> wrote:
> And, can I ask u one futher question? what's the mean of []?
>
> relationalExpression
> : shiftExpression
> (
> (
> ( LT^ | GT^ | LE^ | GE^ )
> shiftExpression
> )*
> |
> "instanceof"^ typeSpec[true]
> )
> ;
More information about the antlr-interest
mailing list