dcsimg
BUG - .NET exception when creating Lexer with exactly 2 tokens
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Oliver_Wegner
Posted On:   Saturday, October 23, 2004 08:39 AM

Hi everybody, Yesterday I came across a problem with antlr (2.7.4) and I think we have a bug here. I hope I am not mistaken ;) Anyway, I could isolate the problem somewhat. Look at this grammar file: options { language="CSharp"; } class MyParser extends Parser; options { buildAST=true; } rule1 : (LIT1)+ ; class MyLexer extends Lexer; options { charVocabulary='\0'..'255'; caseSensitive=false; } LIT1 : '-' ; LIT2 : '_' ; /*LIT3 : 'x' ;*/    More>>

Hi everybody,


Yesterday I came across a problem with antlr (2.7.4) and I think we have a bug here. I hope I am not mistaken ;)


Anyway, I could isolate the problem somewhat. Look at this grammar file:



			
options {
language="CSharp";
}

class MyParser extends Parser;

options {
buildAST=true;
}

rule1
: (LIT1)+
;

class MyLexer extends Lexer;

options {
charVocabulary='\0'..'255';
caseSensitive=false;
}

LIT1
: '-'
;

LIT2
: '_'
;

/*LIT3
: 'x'
;*/




Note that there are exactly two tokens (LIT1 and LIT2) defined in the Lexer part, since LIT3 is commented out. Now look at the CSharp file/class which makes use of the generated lexer and parser:



			
using System;

class MainClass
{
public static void Main(string[] args)
{
dosomething();
}

private static void dosomething() {
MyLexer lexer;
MyParser parser;

Console.WriteLine("1. Before creating Lexer...");
lexer=new MyLexer(Console.OpenStandardInput());
Console.WriteLine("2. Lexer created. Before creating Parser...");
parser=new MyParser(lexer);
Console.WriteLine("3. Parser created. Start parsing...");
parser.rule1();
Console.WriteLine("4. Parsing done.");
}

}




So actually what happens when I compile this and start it is that at the point when the parser is about to created (parser=new MyParser(lexer);) then I get the following output/exception:



			
1. Before creating Lexer...
2. Lexer created. Before creating Parser...

Unhandled Exception: System.ArgumentException: Source array was not long enough. Check srcIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at antlr.ASTFactory.setMaxNodeType(Int32 NodeType) in c:Download!notebookantlrantlr-2.7.4libcsharpsrcantlrASTFactory.cs:line 193
at MyParser.initializeASTFactory(ASTFactory factory) in c:Dsrc
etantlrtestMyParser.cs:line 111
at MyParser.initializeFactory() in c:Dsrc
etantlrtestMyParser.cs:line 107
at MyParser.initialize() in c:Dsrc
etantlrtestMyParser.cs:line 35
at MyParser..ctor(TokenStream lexer, Int32 k) in c:Dsrc
etantlrtestMyParser.cs:line 50
at MyParser..ctor(TokenStream lexer) in c:Dsrc
etantlrtestMyParser.cs:line 53


at DefaultNamespace.MainClass.dosomething() in c:Dsrc
etantlrtestMain.cs:line 29
at DefaultNamespace.MainClass.Main(String[] args) in c:Dsrc
etantlrtestMain.cs:line 19




Anyway, what I found out is that this Exception occurs only when I have exactly two tokens defined in the lexer. When I remove for example LIT2 then the exception will not occur. Neither will it when LIT3 is actually defined as a third token. Neither will it when I do not set buildAST to true in the parser options.


I am running antlr 2.7.4 on the Microsoft .NET Framework 1.1 on a Windows 2000 Machine.


I can send the whole bunch of files to anyone who requests it.


Best regards,


Oliver

   <<Less
About | Sitemap | Contact