[antlr-interest] return result of a rule reference directly

Hugo Leeney hugo.leeney at gmail.com
Fri Jun 2 10:22:02 PDT 2006


Hi, Thanks for the reply,

Actually the code I posted before produces an error. It should have
been what you suggested. I messed around with it some more and didn't
come up with anything. The generated code I am looking for would look
like:

void MyParser::rule1() {
    /*NAMESPACE STUFF...*/
    try {
        return rule2();
    }
    catch ( .....

Like you alluded to I don't think it is possible unless there is a
special bit of ANTLR syntax I have missed. It wouldn't be too hard to
generate that kind of code I don't think. Suggestion for syntax
follows:

rule1
returns[string] //For method interfaces
{} :
    return rule2 //similar to  'x=rule2' syntax
...
;

I know everything I want to do is possible using ASTs but I am looking
for efficient parsing with BIG files. I could pass the information up
by creating variables at each level but this is not ideal. I hope you
get my meaning.


On 6/2/06, Martin Probst <mail at martin-probst.com> wrote:
> > I was wondering is it possible to return the result of a rule
> > reference directly (without instantiating a variable).
>
> The problem is with the generated code, which has code paths that
> don't go through the assignment. However, you can reduce bloat by
> initializing it (I presume you mean initializing, no?) in the
> declaration, e.g.
>
> yellow_rule
> returns [String name = ""]
> :
>   ....
>
> Regards,
> Martin
>


-- 
*******************************************
This document is strictly confidential and is intended for use by
 the addressee unless otherwise indicated.
*******************************************


More information about the antlr-interest mailing list