[antlr-interest] (newbie question) where can SLIST get its information from?
Kay Roepke
kroepke at classdump.org
Sun Jul 8 10:44:23 PDT 2007
Hi!
On Jul 8, 2007, at 5:30 PM, ali azimi wrote:
> If there is no left curly in some rule, where can an imaginary
> node SLIST get its line and column information from? for example,
> in the following rewrite rule, what can I put instead of question
> mark in front of lc=?
>
> textualsystemdefinition
> :lc=? packagereferenceclause*('system' systemname end
> entityinsystem+ 'endsystem'(systemname)?end|typebasedsystemdefinition)
> ->^(SLIST[$lc] packagereferenceclause* 'system'systemname end
> entityinsystem+ 'endsystem' systemname? end typebasedsystemdefinition)
> ;
As you don't have an explicit token reference you will need to use
the first token that has been matched by textualsystemdefinition.
Consider this grammar:
grammar ASTConst;
options {
output=AST;
ASTLabelType=CommonTree;
}
tokens {
SLIST;
}
rule
: subrule? subrule1 -> ^(SLIST[$rule.start] subrule? subrule1)
;
subrule
: 'A';
subrule1
: 'B';
$rule.start refers to the first token that has been matched by rule,
making it the ideal candidate for your purposes :)
(For reference: Page 130 in the ANTLR book lists the predefined
parser rule attributes. Among those is start. Haven't looked whether
this
is in the wiki already.)
HTH,
-k
--
Kay Röpke
http://classdump.org/
More information about the antlr-interest
mailing list