[antlr-interest] adding node to AST
Bryan Ewbank
ewbank at gmail.com
Fri Dec 2 07:40:26 PST 2005
Hi Donal,
Since you're calling it a *token* rather than a sequence of tokens, it
seems you should be gathering these in the lexer - or is arbitrary
whitespace between the elements allowed, like this:
SubscriptionManager
: 2345
{ }
... ... ...
Assuming that this is a *token*, rather than a sequence of tokens,
something like the following will work:
// somewhat abstract lex syntax; sorry...
SubscriptionManager:[0-9][0-9]* { return SUBSCRIPTION_MANAGER; }
This way, every token that starts with SubscriptionManager: and has a
trailing integer component will be folded into one abstract token, and
allows your grammar to look like this:
subscriptionManager!
x:SUBSCRIPTION_MANAGER^ LBRACE! (subscriptionLevel)* RBRACE!
| "SubscriptionManager"
{
// choke and die here!;
}
;
This results in a parent node of SUBSCRIPTION_MANAGER, containing the
appropriate string, and the trees produced by the <subscriptionLevel>
elements are the children:
[SUBSCRIPTION_MANAGER,"SubscriptionManager:01"]
[SUBSCRIPTION_LEVEL, ... ]
[SUBSCRIPTION_LEVEL, ... ]
[SUBSCRIPTION_LEVEL, ... ]
Hope this helps,
- Bryan Ewbank
More information about the antlr-interest
mailing list