[antlr-interest] (no subject)

David Marín Carreño dmarin at sice.com
Fri Sep 18 00:28:44 PDT 2009


At 22:59 17/09/2009, Gavin Lambert wrote:
> 
> Match the tree and skip the statements:
> 
> conditionalifthen:
>    ^(IF expression ( { $expression.value != 0 }?
> => ^(THEN statements) | ^(THEN .*)));
> 
> conditionalifthenelse:
>    ^(IFELSE expression
>      ( { $expression.value != 0 }? => ^(THEN
> statements) ^(ELSE .*) |
>                                      ^(THEN .*)
> ^(ELSE statements) ));

OK. I've tried this code, but both ANTLR 3.1.2 and 3.1.3 generate a faulty
tree parser, as they don't declare a "expression" variable in the
corresponding specialStateTransition function. 

I think this is a bug. How can I report it?


But, finally, for the record, I have a functional solution.

First of all, I have defined a new private member for the Tree Parser class.

@members {
	...
	private boolean lastCondExp = false;
	...
}

And I use it for save the last conditional expression:

conditionalifthen:
   ^(IF expression {lastCondExp = ($expression.value!=0);} 
		( {lastCondExp}? => ^(THEN statements) |
^(THEN .*)));
 
conditionalifthenelse:
   ^(IFELSE expression {lastCondExp = ($expression.value!=0);}
     		( { lastCondExp }? => ^(THEN statements) ^(ELSE .*) |
                                      ^(THEN .*) ^(ELSE statements) ));


Thanks all for your help!
--
David Marín Carreño



More information about the antlr-interest mailing list