[antlr-interest] use of += with * in C#

Gavin Lambert antlr at mirality.co.nz
Fri Feb 15 15:24:17 PST 2008


At 12:18 16/02/2008, Benjamin Shropshire wrote:
 >document
 >    :
 >    (i += import)*
 >     EOF
 >      {foreach(string t in $i) Console.Write("\n>>"+(t));}
 >    ;
 >
 >import returns [string s]
 >    : 'import' (' ' | '\t')+ FText eol_ {$s=$FText.Text;}
 >    ;

$i is not a list of strings, it is a list of "import rule return 
structures".  (And I'm not exactly sure what type name that is; 
you'll need to check the generated code.)  This is partly because 
rules are permitted to return multiple things.

So you'd need to change the code in the document rule to:

   foreach (someType t in $i) Console.Write("\n>>" + t.s);

(replacing someType with the actual return type of the import 
rule.)



More information about the antlr-interest mailing list