[antlr-interest] ANTLR3.0b5 - Embedding on parser within another one (Parser nesting)

alexander.berger at finnova.ch alexander.berger at finnova.ch
Tue Nov 28 23:28:45 PST 2006


Hi Kay

Thank you for your answer. Of course you are right, but it is not what I
intended to do. The problem is not to force antlr to use the return value
of a rule as the resulting tree. The Problem is within the called rule to
force antlr to set the resulting tree to the one returned by the embedded parser. 

My next approach was the following one:

  start2 : 
	x=subParser -> $x
	;


  subParser : 
		'do' { 
			PLangParser p = new PLangParser(this.getTokenStream());
			p.setTreeAdaptor(this.getTreeAdaptor());
			Object t = p.start().getTree();
			$tree = t;
		}
	;

in this case nearly everything went alright but eventually at the end of 
the generated java code for the rule the following statement

	retval.tree = (Object)adaptor.rulePostProcessing(root_0);

made all my work into void :-(.
So I recognized that funny "root_0" variable and modified the rule like
this:

  start2 : 
	x=subParser -> $x
	;


  subParser : 
		'do' { 
			PLangParser p = new PLangParser(this.getTokenStream());
			p.setTreeAdaptor(this.getTreeAdaptor());
			Object t = p.start().getTree();
			root_0 = t;
		}
	;

And horray it worked the way I expected it, but I think that using "root_0" is very intrusive and not the way to go. So I am still wondering if there 
is a way to do things like that in a non-intrusive way.

Kind Regards
Alex
____________________________________________

finnova AG Bankware
Alexander Berger
SR-Peripheral-Team 

Sägestrasse 22, CH-5600 Lenzburg
Tel: +41 62 886 4807 / Fax: +41 62 886 4888 mailto:alexander.berger at finnova.ch
http://www.finnova.ch 
-----Ursprüngliche Nachricht-----
Von: Kay Roepke [mailto:kroepke at classdump.org] 
Gesendet: Dienstag, 28. November 2006 16:45
An: Berger Alexander
Cc: antlr-interest at antlr.org; alex-berger at gmx.ch
Betreff: Re: [antlr-interest] ANTLR3.0b5 - Embedding on parser within another one (Parser nesting)


On 28. Nov 2006, at 16:17 , alexander.berger at finnova.ch wrote:

> but in the rewrite instruction '-> $x.expression' antlr complains  
> with the following error message:
>
> error(100): PLang.g3:111:19: syntax error: antlr: PLang.g3:111:19:  
> unexpected token: .
>
> In other words, in the rewrite instruction "x=subParser ->  
> $x.expression"
> antlr does not allow to use the return value as output Tree.

This is a bit obscure, I agree. Needs documentation.

Try using

start :
	x=subParser -> {$x}
	;

That should treat the return value of subParser as a tree.

HTH,

-k

-- 
Kay Röpke
http://classdump.org/






More information about the antlr-interest mailing list