[antlr-interest] extracting invocations from an expression

Benoit Fouletier benblo+ANTLR at gmail.com
Tue Aug 11 15:26:52 PDT 2009


I have cascading rules that define operator precedence in an expression
(taken from the C# parser example), like so:
*           thisLevelExpression :*
*               nextHigherPrecedenceExpression (OPERATOR
nextHigherPrecedenceExpression)* ;*

I managed to isolate where method invocation takes place, and now I'd like
to insert some tokens to wrap around specific invocations, so that:

*a.b().c()*

would be translated to:

*[invoke: [invoke: a.b() ].c() ]*

or something like that.

It seems to me like I should follow the precedence pattern to insert a new
rule, unfortunately the invocation part is at the end of the precedence
chain, so I can't figure out how.
Here are the rules I've isolated:

*primaryExpression*
* **:** **basicPrimaryExpression*
* **(** **options { greedy = true; } : *
* **(** **LPAREN argumentList? RPAREN** **// invocationExpression <---- THIS
IS THE ONE!!*
* **|** **LBRACK expressionList RBRACK** **// elementAccess*
* **|** **DOT identifier** **// memberAccess*
* **|** **INC ** **// postIncrementExpression*
* **|** **DEC** **// postDecrementExpression*
* **)*
* **)**
* **;*
*
*
*basicPrimaryExpression*
* **:** **literal*
* **|** **identifier** **// simpleName*
* **|** **LPAREN assignmentExpression RPAREN** **// parenthesizedExpression*
* **|** **THIS** **// thisAccess*
* **|** **newExpression*
* **;*


Sorry for the cry for help, my brain is in total meltdown at the moment...

        Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090812/a923f0e7/attachment.html 


More information about the antlr-interest mailing list