public static IParseTree <Symbol> Build(Source.IOrigin origin) { var sanitizedTokens = SanitizedTokens(origin); // Assume every list from tupple is of size 1 !!! var leafs = sanitizedTokens.Select(r => { Debug.Assert(r.Item2.Count() == 1); return(new ParseLeaf <Symbol>(r.Item1, new Symbol(r.Item2.First()))); }); var grammar = new Grammar <Symbol>( NicodemGrammarProductions.StartSymbol(), NicodemGrammarProductions.MakeProductionsDictionaryForGrammarConstructor()); var parser = new LlParser <Symbol>(grammar); var parseRes = parser.Parse(leafs); if (parseRes is OK <Symbol> ) { return((parseRes as OK <Symbol>).Tree); } else { var err = parseRes as Error <Symbol>; Console.WriteLine(ParserUtils <Symbol> .PrepareErrorMessage(err)); return(null); } }
public void Init() { TestsTraceListener.Setup(); builder = new ASTBuilder(); grammar = new Grammar <Symbol>( NicodemGrammarProductions.StartSymbol(), NicodemGrammarProductions.MakeProductionsDictionaryForGrammarConstructor()); dummyFrag = new DummyFragment("dummy"); dummyProd = null; operatorSymbol = new UniversalSymbol[] { P.Operator0Expression, P.Operator1Expression, P.Operator2Expression, P.Operator3Expression, P.Operator4Expression, P.Operator5Expression, P.Operator6Expression, P.Operator7Expression, P.Operator8Expression, P.Operator9Expression, P.Operator10Expression, P.Operator11Expression, P.Operator12Expression, P.Operator13Expression, P.Operator14Expression, P.Operator15Expression, P.Operator16Expression, P.Operator17Expression, P.Operator18Expression, P.Operator19Expression }; }
private static Grammar <Symbol> MakeGrammar() { return(new Grammar <Symbol>( NicodemGrammarProductions.StartSymbol(), NicodemGrammarProductions.MakeProductionsDictionaryForGrammarConstructor())); }