public override Choice GetEBNFBlock(GrammarAST ebnfRoot, IList <CodeBlockForAlt> alts) { if (!g.tool.force_atn) { int decision; if (ebnfRoot.Type == ANTLRParser.POSITIVE_CLOSURE) { decision = ((PlusLoopbackState)ebnfRoot.atnState).decision; } else if (ebnfRoot.Type == ANTLRParser.CLOSURE) { decision = ((StarLoopEntryState)ebnfRoot.atnState).decision; } else { decision = ((DecisionState)ebnfRoot.atnState).decision; } if (AnalysisPipeline.Disjoint(g.decisionLOOK[decision])) { return(GetLL1EBNFBlock(ebnfRoot, alts)); } } return(GetComplexEBNFBlock(ebnfRoot, alts)); }
public override Choice GetChoiceBlock(BlockAST blkAST, IList <CodeBlockForAlt> alts, GrammarAST labelAST) { int decision = ((DecisionState)blkAST.atnState).decision; Choice c; if (!g.tool.force_atn && AnalysisPipeline.Disjoint(g.decisionLOOK[decision])) { c = GetLL1ChoiceBlock(blkAST, alts); } else { c = GetComplexChoiceBlock(blkAST, alts); } if (labelAST != null) { // for x=(...), define x or x_list string label = labelAST.Text; Decl d = GetTokenLabelDecl(label); c.label = d; GetCurrentRuleFunction().AddContextDecl(labelAST.GetAltLabel(), d); if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN) { string listLabel = GetTarget().GetListLabel(label); TokenListDecl l = new TokenListDecl(this, listLabel); GetCurrentRuleFunction().AddContextDecl(labelAST.GetAltLabel(), l); } } return(c); }
public virtual void ProcessNonCombinedGrammar(Grammar g, bool gencode) { if (g.ast == null || g.ast.hasErrors) return; if (internalOption_PrintGrammarTree) ConsoleOut.WriteLine(g.ast.ToStringTree()); bool ruleFail = CheckForRuleIssues(g); if (ruleFail) return; int prevErrors = errMgr.GetNumErrors(); // MAKE SURE GRAMMAR IS SEMANTICALLY CORRECT (FILL IN GRAMMAR OBJECT) SemanticPipeline sem = new SemanticPipeline(g); sem.Process(); if (errMgr.GetNumErrors() > prevErrors) return; // BUILD ATN FROM AST ATNFactory factory; if (g.IsLexer()) factory = new LexerATNFactory((LexerGrammar)g); else factory = new ParserATNFactory(g); g.atn = factory.CreateATN(); if (generate_ATN_dot) GenerateATNs(g); // PERFORM GRAMMAR ANALYSIS ON ATN: BUILD DECISION DFAs AnalysisPipeline anal = new AnalysisPipeline(g); anal.Process(); //if ( generate_DFA_dot ) generateDFAs(g); if (g.tool.GetNumErrors() > prevErrors) return; // GENERATE CODE if (gencode) { CodeGenPipeline gen = new CodeGenPipeline(g); gen.Process(); } }