[antlr-interest] Problems with implementing 'include' directiveusing C#

julien.degroote at fortis.com julien.degroote at fortis.com
Wed Jun 20 04:10:40 PDT 2007


Hi, 

You need to add this : 

@header {
using System.Collections.Generic;
}

right after the options {} of your grammar.

Regards,
 
Julien

-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of amartinez at atc.ugr.es
Sent: Wednesday, June 20, 2007 1:00 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Problems with implementing 'include' directiveusing C#

Hello,

I'm working on a little ANTLR v3 project and need to implement the
'include' directive (it's a simple assembler). I'm using ANTLR's C# output
(using Mono and Linux).
I have tried to addapt (to C#) Terence's java sample for implementing
'include' directive without sucess:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=557057

When compiling Mono's gmcs trows this error:

error CS0246: The type or namespace name `Stack`1' could not be found. Are
you missing a using directive or an assembly reference?


I attach the piece of code. Any idea?

The code is compiled using:
gmcs *cs  -r:Antlr3.Runtime.dll -r:antlr.runtime.dll -r:StringTemplate.dll
-r:Antlr3.Utility.dll


//From Terence's sample
@lexer::members {
    class SaveStruct {

      SaveStruct(ICharStream input){
        this.input = input;
        this.marker = input.mark();
      }
      public ICharStream input;
      public int marker;
     }

    Stack<SaveStruct> includes = new Stack<SaveStruct>();

    // We should override this method for handling EOF of included file
     public Token nextToken(){
       Token token = super.nextToken();

       if(token==Token.EOF_TOKEN && !includes.empty()){
        // We've got EOF and have non empty stack.
         SaveStruct ss = includes.pop();
         setCharStream(ss.input);
         input.rewind(ss.marker);
         token = super.nextToken();
       }

      // Skip first token after switching on another input.
       if(((CommonToken)token).getStartIndex() < 0)
         token = super.nextToken();

       return token;
     }
 }

--
Antonio Martínez
-------------- next part --------------

= = = = = = = = = = = = = = = = = = = = = = = = =
Fortis disclaimer :
http://www.fortis.be/legal/disclaimer.htm

Privacy policy related to banking activities of Fortis:
http://www.fortis.be/legal/privacy_policy.htm
= = = = = = = = = = = = = = = = = = = = = = = = =



More information about the antlr-interest mailing list