[antlr-interest] Operator tree construction in rewrite syntax

Marko Simovic markobarko at gmail.com
Tue Apr 15 13:43:12 PDT 2008


hmmm...that makes sense to me. however, i'm running into a problem.

given input:

abc+

which is incomplete input, the parser fails in two different ways
depending on the tree construction syntax i use.

if i use:
unary: (UnaryOp^)? something;
then i get a noalt exception and i get returned a tree with plus
operator and one operand (abc).

if i use:
unary
	: UnaryOp something -> ^(UnaryOp something)
	| something
	;
then i get a rewriteemptystreamexception and i get no tree (as the
parser doesn't catch the exception and it propagates up to my code).

strange? or perfectly logical?

-----Original Message-----
From: Terence Parr <parrt at cs.usfca.edu>
To: Gavin Lambert <antlr at mirality.co.nz>
Cc: Marko Simovic <markobarko at gmail.com>, antlr-interest
<antlr-interest at antlr.org>
Subject: Re: [antlr-interest] Operator tree construction in rewrite
syntax
Date: Tue, 15 Apr 2008 12:47:39 -0700


On Apr 15, 2008, at 12:41 PM, Gavin Lambert wrote:

> At 04:20 16/04/2008, Marko Simovic wrote:
>> also, while we're on the subject, what about a rewrite syntax of  
>> this one:
>>
>> unary: (UnaryOp^)? something;
>
> That one's simpler, because there aren't any loops (so no need to  
> generate multiple trees):
>
> unary
>  :  UnaryOp s1=something -> ^(UnaryOp $s1)
>  |  s2=something -> $s2
>  ;

or

unary
	: UnaryOp something -> ^(UnaryOp something)
	| something
	;

in 2nd alt, ANTLR just adds to tree.

Ter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080415/8134876a/attachment.html 


More information about the antlr-interest mailing list