[antlr-interest] List Label (+=) without specifying grammar output

Conrad Benham cfbenham at yahoo.com.au
Tue Jun 5 05:24:19 PDT 2007


Hi,

 

I'm  having  difficulty in collecting recurring parameters  using the list label operator (+=). I have a tree walker that is walking an  AST.  There is an expression (expr) rule that can have  multiple expressions as parameters (yes, it is a recursive grammar). For  example, the abbreviated form of the (Java-based) tree walking grammar looks like  this: 



tree grammar TreeWalker;

options {

    tokenVocab=SampleGrammar;

    ASTLabelType=CommonTree;

}



expr returns (Object value)

  : ^(word=TOKEN args+=expr*)   {value =  javaObject.evaluate($word, $args);}

  ;  



As can be seen no output is specified in the   grammar options directives section. When generating this,  ANTLR  reports the grammar does not have the output  option specified for 'args'. The exact error is: rule '+=' list labels are not  allowed w/o output option: args I believe this error is emitted when no output is specified and a rule only returns a single value.
 

  From reading the thread: http://www.antlr.org/pipermail/antlr-interest/2007-April/020070.html it seems that list labels are  geared at collecting tokens as opposed to the result of evaluating  rules. Is it really ambiguous to collect the result of expr in a collection using list labels (+=), as discussed in the above-mentioned thread?  What is the recommended approach to collecting multiple return values in this case? 

 Thanks,

 Conrad




      
_________________________________________________________________________________              

How would you spend $50,000 to create a more sustainable environment in Australia? Go to Yahoo!7 Answers and share your idea.
http://advision.webevents.yahoo.com/aunz/lifestyle/answers/y7ans-babp_reg.html





More information about the antlr-interest mailing list