CoreParser.ExecuteAction - Context.CurrentParserState is null!

May 4, 2010 at 3:02 AM

I've been trying to get the parser to generate an AST for a script, but when I call Evaluate on my ScriptInterpreter, I get a null reference exception in CoreParser.ExecuteAction - it appears that Context.CurrentParserState is null! Seeing as CurrentParserState is read-only, how do I get the parser to start with some sort of state???

var g = new Se5Grammar();
var i = new ScriptInterpreter(g);
i.Parser.Scanner.Data.LineTerminatorsArray = "\n".ToArray();
i.ParseMode = ParseMode.File;
i.Script = File.ReadAllText("Script_Main_ExternalEvents.txt");
var pms = i.GetParserMessages();
foreach (var pm in pms)
The Se5Grammar class is the subclass of Grammar I created for the script language, of course... if you need to see that code too, I can certainly provide it; it's just a bit long! ;)

May 4, 2010 at 3:12 AM

Well, you certainly do it the wrong way. Look at the code in grammar explorer combined with code in Grammar.RunSample to see how to execute the script for a grammar. Just follow execution of some expression in ExpressionEvaluator grammar, step-by-step in debugger


May 4, 2010 at 1:40 PM

Aha! Thanks, I found that by running this code:

var g = new Se5Grammar();
var lang = new LanguageData(g);
var p = new Parser(lang);
foreach (var err in p.Language.Errors)
it was revealed that I have an error in the grammar itself (one of my nonterminals had an uninitialized Rule property)!