System.StackOverFlow in ANTLR(Lexer class file)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmayur
    New Member
    • Mar 2008
    • 1

    System.StackOverFlow in ANTLR(Lexer class file)

    I'm using ANTLR parser for a txt file of around 5 MB. My main grammer module contains displaying contents between START_TAG(<) and END_TAG(>).

    fragment ELEMENT
    : (
    [code=cpp]
    (ELEMENT
    | t=PCDATA
    { Console.Out.Wri teLine("PCDATA: \""+$t.Text+"\" "); }
    //| t=CDATA
    // { Console.Out.Wri teLine("CDATA: \""+$t.Text+"\" "); }
    // | t=COMMENT
    // { Console.Out.Wri teLine("Comment : \""+$t.Text+"\" "); }
    //| pi=PI
    )*
    END_TAG[/B]
    )
    [/code]
    When the grammer is converted to a C# code, the Lexer class file contains mELEMENT() method which contains the below code.
    [code=cpp]
    public void mELEMENT() // throws RecognitionExce ption [2]
    {
    Token t = null;
    mSTART_TAG();
    // On some particular condition.
    switch (alt4)
    {
    case 1 :
    {
    mELEMENT();
    }
    break;
    case 2 :
    {
    int nameStart125 = CharIndex;
    mPCDATA();
    t = new CommonToken(inp ut, Token.INVALID_T OKEN_TYPE, Token.DEFAULT_C HANNEL, nameStart125, CharIndex - 1);
    Console.Out.Wri teLine(t.Text); }
    break;
    // Some conditions
    mEND_TAG();
    }
    }
    [/code]
    After displaying contents of around 500 KB, a StackOverFlow error is being displayed at CommonToken() method. But the Call Stack points at mELEMENT().
    Is the error because of the recursive call of mELEMENT() method or is there a problem the grammer or is there a problem in CommonToken() method?

    Thanks in advance.

    Regards,
    Mayur
    Last edited by sicarie; Mar 10 '08, 03:28 PM. Reason: Code tags, removed annoying and unnecessary editing, and moved to .NET Forum.
Working...