[antlr-interest] An object reference is required for the nonstatic field, method, or property 'Antlr.Runtime.Debug.DebugParser.dbg'

Fatih Tolga fatih at tullab.com
Fri Sep 7 14:06:01 PDT 2007


Hi everybody,
I've just started to learn ANTLR. I am going on the tutorials in the 
site. Firstly, I tried to debug an c# project. ANTLRWorks generated the 
code with "-debug" option. This is the grammer that is in the tutorial:

grammar Test;

options
{language = 'CSharp';
output=AST;
}
expr : mexpr (PLUS^ mexpr)* SEMI!
;
mexpr
: atom (STAR^ atom)*
;
atom: INT
;
//class csharpTestLexer extends Lexer;
WS : (' '
| '\t'
| '\n'
| '\r')
{ channel = HIDDEN; }
;
LPAREN: '('
;
RPAREN: ')'
;
STAR: '*'
;
PLUS: '+'
;
SEMI: ';'
;
protected
DIGIT
: '0'..'9'
;
INT : (DIGIT)+
;


When I tried to build the generated c# code, an error occured in the 
parser codes. This is the line where the error occured:
    protected ITreeAdaptor adaptor = new DebugTreeAdaptor(dbg, new 
CommonTreeAdaptor());

This is the error message:
An object reference is required for the nonstatic field, method, or 
property 'Antlr.Runtime.Debug.DebugParser.dbg'

I moved "new DebugTree..." part to the constructor of the Parser like that:
    public TestParser(ITokenStream input, IDebugEventListener dbg)
        : base(input, dbg)
    {
        this.adaptor = new DebugTreeAdaptor(dbg, new CommonTreeAdaptor());
    }

This time it compiled but another error occured:
'Test.exe' does not contain a static 'Main' method suitable for an entry 
point

What should/would I do?

Regards.



More information about the antlr-interest mailing list