[antlr-interest] AST NODE CHOICE
    Ric Klaren 
    klaren at cs.utwente.nl
       
    Wed Jul  9 06:09:41 PDT 2003
    
    
  
On Wed, Jul 09, 2003 at 12:47:52PM -0000, colettekirwan wrote:
> I was wondering is it possible using the antlr grammar to  generate a 
> tree node based on a choice i.e
> 
> I have the following grammar in my Parser
> 
> test_statement:!
>  e2:node1_list e1:node2_list e3:(node3_list | node4_list)
>         {## = #([TEST_STATEMENT,"TEST_STATEMENT"],#e2,#e1,#e3);}
>        
>  ; 
> 
> I want the last node e3 to be either node3_list or node4_list 
> depending on the User's input. The above grammar compiles but does 
> not work i.e my Parser code does not generate any code relating to e3.
Labeled subrules do not work e.g. label:( x|y|z ).
Something like this should do the job if I understood the problem correctly
(assuming java & I did not typo/laps in C++ somewhere):
e2:node1_list e1:node2_list (e3:node3_list | e4:node4_list)
{
	AST t;
	if ( #e3 )
		t = #e3;
	else
		t = #e4;
	## = #([TEST_STATEMENT,"TEST_STATEMENT"],#e2,#e1,t);
}
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  Before they invented drawing boards, what did they go back to?
 
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
    
    
More information about the antlr-interest
mailing list