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

Benjamin Shropshire shro8822 at vandals.uidaho.edu
Fri Feb 15 15:18:01 PST 2008


I can't seem to make antler generate usable action rules for grammars 
with +=.

what I;m trying is this:

grammar test_g;
options
{
    language=CSharp;
    backtrack=false;
    output=AST;
}

tokens {
Import        =    'import';
NewLine        =    '\r\n';
}

WS        :    (' ' | '\t')+;
GText        :    '//' ~('\n' | '\r')*;
FText        :    ('A'..'Z' | 'a'..'z')*;

document
    :
    (i += import)*
     EOF
      {foreach(string t in $i) Console.Write("\n>>"+(t));}
    ;

import returns [string s]
    : 'import' (' ' | '\t')+ FText eol_ {$s=$FText.Text;}
    ;

eol_
    : GText? '\r\n'
    ;


====

The problem is that the thing that 'import' generates and 'document' 
accumulates in the variable 'i' is not a C# string, in fact 'i' seems to 
accumulate a set of null pointers.

What am I doing wrong?? Near as I can tell, I'm making some sort of 
really bad assumption about what antlr is expecting, but I'm not seeing 
where it is.

(BTW, the manual hasn't yet been of much help in this)


More information about the antlr-interest mailing list