[antlr-interest] Problems with implementing 'include' directive using C#
amartinez at atc.ugr.es
amartinez at atc.ugr.es
Wed Jun 20 03:59:49 PDT 2007
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
More information about the antlr-interest
mailing list