Cannot get GWBasicGrammer to run

Nov 4, 2009 at 11:30 PM

I am trying to get a GWBasicGrammar script running, but am getting as exception due to a null AST. I can't figure out how to fix this. I've looked at The ExpresionEvaluatorGrammar and the MiniPython and they seem similar, but something is different.

 

The code I'm using to create the grammer is this:

 

GWBasicGrammar grammar = new GWBasicGrammar();
ScriptInterpreter interpreter = new ScriptInterpreter(grammar);
ParseTree parseTree = interpreter.Parser.Parse("1 H=10");

string lastResult = grammar.RunSample(parseTree);

 

 

When calling RunSample I am getting an exception in the Evaluate method of ScriptInerpreter:

    public void Evaluate(ParseTree parsedScript) {
      int start = Environment.TickCount;
      try {
        ParsedScript = parsedScript;
        Check(ParsedScript != null, "Parsed tree is null, cannot evaluate.");
        UpdateStatusFromParseStatus();
        if (Status != InterpreterStatus.Evaluating) return;
        Check(ParsedScript.Root != null, "Parse tree root is null, cannot evaluate.");
        var astNode = ParsedScript.Root.AstNode;
        Check(astNode != null, "Root AST node is null, cannot evaluate.");

The AstNode is null.

 

Any help on how to work around that would be great.

Nov 4, 2009 at 11:47 PM

Have you tried setting adding Parsing.LanguageFlags.CreateAst to the LanguageFlags in the grammar? Like so:

this.LanguageFlags = LanguageFlags.NewLineBeforeEOF | Parsing.LanguageFlags.CanRunSample | Parsing.LanguageFlags.CreateAst;

I did that and it worked.

Good luck!

 

Coordinator
Nov 5, 2009 at 3:18 AM
Edited Nov 5, 2009 at 3:33 AM

hm... are u talking to yourself, or there's somebody else in the room? :)