// // For version 1.0.1 recognize any line-end character if /unicode // static void AddAnchorContext(NfsaInstance nInst, NState endS, RuleDesc rule) { NState nEnd = nInst.MkState(); Leaf temp = new Leaf(RegOp.charClass); temp.rangeLit = RangeLiteral.RightAnchors; nInst.MakePath(temp, endS, nEnd); nInst.MarkAccept(nEnd, rule); nEnd.rhCntx = 1; }
internal void AddLexRule(LexSpan name, RuleDesc desc) { var r = new LexRule(); r.Line = name.startLine; r.Column = name.startColumn + 1; r.Position = name.startIndex; r.Symbol = name.ToString(); r.Desc = desc; lexRules.Add(r); lexRuleMap.Add(desc, r); }
protected override void DoAction(int action) { switch (action) { case 4: // DefinitionSection -> DefinitionSeq, "%%" { isBar = false; typedeclOK = false; } break; case 5: // DefinitionSection -> "%%" { isBar = false; } break; case 6: // DefinitionSection -> error, "%%" { handler.ListError(LocationStack[LocationStack.Depth - 2], 62, "%%"); } break; case 7: // RulesSection -> Rules, "%%" { typedeclOK = true; } break; case 8: // UserCodeSection -> CSharp { aast.UserCode = LocationStack[LocationStack.Depth - 1]; } break; case 9: // UserCodeSection -> /* empty */ { /* empty */ } break; case 10: // UserCodeSection -> error { handler.ListError(LocationStack[LocationStack.Depth - 1], 62, "EOF"); } break; case 13: // Definition -> name, verbatim { AddLexCategory(LocationStack[LocationStack.Depth - 2], LocationStack[LocationStack.Depth - 1]); } break; case 14: // Definition -> name, pattern { AddLexCategory(LocationStack[LocationStack.Depth - 2], LocationStack[LocationStack.Depth - 1]); } break; case 15: // Definition -> "%x", NameList { AddNames(true); } break; case 16: // Definition -> "%s", NameList { AddNames(false); } break; case 17: // Definition -> "%using", DottedName, ";" { aast.usingStrs.Add(LocationStack[LocationStack.Depth - 2].Merge(LocationStack[LocationStack.Depth - 1])); } break; case 18: // Definition -> "%namespace", DottedName { aast.nameString = LocationStack[LocationStack.Depth - 1]; } break; case 19: // Definition -> "%visibility", csKeyword { aast.AddVisibility(LocationStack[LocationStack.Depth - 1]); } break; case 20: // Definition -> "%option", verbatim { ParseOption(LocationStack[LocationStack.Depth - 1]); } break; case 21: // Definition -> PcBraceSection { aast.AddCodeSpan(Dest, LocationStack[LocationStack.Depth - 1]); } break; case 22: // Definition -> DefComment { aast.AddCodeSpan(Dest, LocationStack[LocationStack.Depth - 1]); } break; case 23: // Definition -> IndentedCode { aast.AddCodeSpan(Dest, LocationStack[LocationStack.Depth - 1]); } break; case 24: // Definition -> "%charClassPredicate", NameList { AddCharSetPredicates(); } break; case 25: // Definition -> "%tokentype", csIdent { aast.SetTokenTypeName(LocationStack[LocationStack.Depth - 1].ToString()); } break; case 26: // Definition -> "%scannertype", csIdent { aast.SetScannerTypeName(LocationStack[LocationStack.Depth - 1].ToString()); } break; case 27: // Definition -> "userCharPredicate", csIdent, "[", DottedName, "]", DottedName { aast.AddUserPredicate(LocationStack[LocationStack.Depth - 5].ToString(), LocationStack[LocationStack.Depth - 3], LocationStack[LocationStack.Depth - 1]); } break; case 28: // IndentedCode -> lxIndent, CSharp, lxEndIndent { CurrentLocationSpan = LocationStack[LocationStack.Depth - 2]; } break; case 29: // IndentedCode -> lxIndent, error, lxEndIndent { handler.ListError(LocationStack[LocationStack.Depth - 2], 64); } break; case 31: // NameList -> error { handler.ListError(LocationStack[LocationStack.Depth - 1], 67); } break; case 32: // NameSeq -> NameSeq, ",", name { AddName(LocationStack[LocationStack.Depth - 1]); } break; case 33: // NameSeq -> name { AddName(LocationStack[LocationStack.Depth - 1]); } break; case 34: // NameSeq -> csNumber { AddName(LocationStack[LocationStack.Depth - 1]); } break; case 35: // NameSeq -> NameSeq, ",", error { handler.ListError(LocationStack[LocationStack.Depth - 2], 67); } break; case 36: // PcBraceSection -> "%{", "%}" { CurrentLocationSpan = BlankSpan; /* skip blank lines */ } break; case 37: // PcBraceSection -> "%{", CSharpN, "%}" { CurrentLocationSpan = LocationStack[LocationStack.Depth - 2]; } break; case 38: // PcBraceSection -> "%{", error, "%}" { handler.ListError(LocationStack[LocationStack.Depth - 2], 62, "%}"); } break; case 39: // PcBraceSection -> "%{", error, "%%" { handler.ListError(LocationStack[LocationStack.Depth - 2], 62, "%%"); } break; case 51: // Rules -> RuleList { rb.FinalizeCode(aast); aast.FixupBarActions(); } break; case 56: // Rule -> ProductionGroup { scope.ClearScope(); /* for error recovery */ } break; case 57: // Rule -> PcBraceSection { rb.AddSpan(LocationStack[LocationStack.Depth - 1]); } break; case 58: // Rule -> IndentedCode { rb.AddSpan(LocationStack[LocationStack.Depth - 1]); } break; case 59: // Rule -> BlockComment { /* ignore */ } break; case 60: // Rule -> "/*...*/" { /* ignore */ } break; case 61: // Production -> ARule { int thisLine = LocationStack[LocationStack.Depth - 1].startLine; rb.LLine = thisLine; if (rb.FLine == 0) { rb.FLine = thisLine; } } break; case 62: // ProductionGroup -> StartCondition, "{", PatActionList, "}" { scope.ExitScope(); } break; case 63: // PatActionList -> /* empty */ { int thisLine = CurrentLocationSpan.startLine; rb.LLine = thisLine; if (rb.FLine == 0) { rb.FLine = thisLine; } } break; case 66: // ARule -> StartCondition, pattern, Action { RuleDesc rule = new RuleDesc(LocationStack[LocationStack.Depth - 2], LocationStack[LocationStack.Depth - 1], scope.Current, isBar); aast.ruleList.Add(rule); rule.ParseRE(aast); isBar = false; // Reset the flag ... scope.ExitScope(); } break; case 67: // ARule -> pattern, Action { RuleDesc rule = new RuleDesc(LocationStack[LocationStack.Depth - 2], LocationStack[LocationStack.Depth - 1], scope.Current, isBar); aast.ruleList.Add(rule); rule.ParseRE(aast); isBar = false; // Reset the flag ... } break; case 68: // ARule -> error { handler.ListError(LocationStack[LocationStack.Depth - 1], 68); scope.ClearScope(); } break; case 69: // StartCondition -> "<", NameList, ">" { List <StartState> list = new List <StartState>(); AddNameListToStateList(list); scope.EnterScope(list); } break; case 70: // StartCondition -> "<", "*", ">" { List <StartState> list = new List <StartState>(); list.Add(StartState.allState); scope.EnterScope(list); } break; case 82: // WFCSharpN -> "(", error { handler.ListError(LocationStack[LocationStack.Depth - 1], 61, "')'"); } break; case 83: // WFCSharpN -> "[", error { handler.ListError(LocationStack[LocationStack.Depth - 1], 61, "']'"); } break; case 84: // WFCSharpN -> "{", error { handler.ListError(LocationStack[LocationStack.Depth - 1], 61, "'}'"); } break; case 85: // DottedName -> csIdent { /* skip1 */ } break; case 86: // DottedName -> csKeyword, ".", csIdent { /* skip2 */ } break; case 87: // DottedName -> DottedName, ".", csIdent { /* skip3 */ } break; case 92: // NonPairedToken -> csKeyword { string text = aast.scanner.yytext; if (text.Equals("using")) { handler.ListError(LocationStack[LocationStack.Depth - 1], 56); } else if (text.Equals("namespace")) { handler.ListError(LocationStack[LocationStack.Depth - 1], 57); } else { if ((text.Equals("class") || text.Equals("struct") || text.Equals("enum")) && !typedeclOK) { handler.ListError(LocationStack[LocationStack.Depth - 1], 58); } } } break; case 106: // Action -> "{", CSharp, "}" { CurrentLocationSpan = LocationStack[LocationStack.Depth - 2]; } break; case 108: // Action -> "|" { isBar = true; } break; case 110: // Action -> "{", error, "}" { handler.ListError(CurrentLocationSpan, 65); } break; case 111: // Action -> error { handler.ListError(LocationStack[LocationStack.Depth - 1], 63); } break; } }
/// <summary> /// Build the NFSA from the abstract syntax tree. /// There is an NfsaInstance for each start state. /// Each rule starts with a new nfsa state, which /// is the target of a new epsilon transition from /// the real start state, nInst.Entry. /// </summary> /// <param name="ast"></param> public void Build(AAST ast) { int index = 0; DateTime time0 = DateTime.Now; nfas = new NfsaInstance[ast.StartStateCount]; foreach (KeyValuePair <string, StartState> p in ast.startStates) { StartState s = p.Value; string name = p.Key; if (!s.IsAll) { NfsaInstance nInst = new NfsaInstance(s, this); nfas[index++] = nInst; nInst.key = name; // for each pattern do ... for (int i = 0; i < s.rules.Count; i++) { RuleDesc rule = s.rules[i]; RegExTree tree = rule.Tree; // This test constructs the disjoint automata // that test code points for predicate evaluation. if (rule.isPredDummyRule) { NState entry = nInst.Entry; nInst.MakePath(tree, entry, entry); } else { NState start = nInst.MkState(); NState endSt = nInst.MkState(); if (tree.op == RegOp.leftAnchor) // this is a left anchored pattern { nInst.AnchorState.AddEpsTrns(start); tree = ((Unary)tree).kid; } else // this is not a left anchored pattern { nInst.Entry.AddEpsTrns(start); } // // Now check for right anchors, and add states as necessary. // if (tree.op == RegOp.eof) { // // <<EOF>> rules are always emitted outside // of the usual subset construction framework. // We ensure that we do not get spurious warnings. // rule.useCount = 1; nInst.eofAction = rule.aSpan; nInst.MakePath(tree, start, endSt); nInst.MarkAccept(endSt, rule); } else if (tree.op == RegOp.rightAnchor) { tree = ((Unary)tree).kid; nInst.MakePath(tree, start, endSt); AddAnchorContext(nInst, endSt, rule); } else { nInst.MakePath(tree, start, endSt); nInst.MarkAccept(endSt, rule); } } } } } if (task.Verbose) { Console.Write("GPLEX: NFSA built"); Console.Write((task.Errors ? ", errors detected" : " without error")); Console.Write((task.Warnings ? "; warnings issued. " : ". ")); Console.WriteLine(TaskState.ElapsedTime(time0)); } if (task.Summary) { WriteSummary(time0); } }
internal void MarkAccept(NState acpt, RuleDesc rule) { acpt.accept = rule; acceptStates.Add(acpt.ord); }
internal void AddRule( RuleDesc rule ) { rules.Add( rule ); }
internal static RuleDesc MkDummyRuleDesc( LexCategory cat, AAST aast ) { RuleDesc result = new RuleDesc(); result.pSpan = null; result.aSpan = aast.AtStart; result.isBarAction = false; result.isPredDummyRule = true; result.pattern = String.Format( CultureInfo.InvariantCulture, "{{{0}}}", cat.Name ); result.list = new List<StartState>(); result.ParseRE( aast ); result.list.Add( aast.StartStateValue( cat.PredDummyName ) ); return result; }
public bool UpdateActiveInActiveRule(RuleDesc objRule) { return(ruleDetails.UpdateActiveInActive(objRule)); }
public bool Update(RuleDesc objRule) { return(ruleDetails.Update(objRule)); }
public bool AddNew(RuleDesc objRule) { return(ruleDetails.AddNew(objRule)); }