static void Main(string[] args) { bool fileArg = false; TaskState task = new TaskState(); OptionState opResult = OptionState.clear; if (args.Length == 0) Usage("No arguments"); for (int i = 0; i < args.Length; i++) { if (args[i][0] == '/' || args[i][0] == '-') { string arg = args[i].Substring(1); opResult = task.ParseOption(arg); if (opResult != OptionState.clear && opResult != OptionState.needCodepageHelp && opResult != OptionState.needUsage) BadOption(arg, opResult); } else if (i != args.Length - 1) Usage("Too many arguments"); else fileArg = true; } if (task.Version) task.Msg.WriteLine("GPLEX version: " + task.VerString); if (opResult == OptionState.needCodepageHelp) CodepageHelp(fileArg); if (opResult == OptionState.errors) Usage(null); // print usage and abort else if (!fileArg) Usage("No filename"); else if (opResult == OptionState.needUsage) Usage(); // print usage but do not abort try { task.Process(args[args.Length - 1]); } catch (Exception ex) { if (ex is TooManyErrorsException) return; Console.Error.WriteLine(ex.Message); throw; } finally { if (task.ErrNum + task.WrnNum > 0 || task.Listing) task.MakeListing(); if (task.ErrNum + task.WrnNum > 0) task.ErrorReport(); else if (task.Verbose) task.Msg.WriteLine("GPLEX <" + task.FileName + "> Completed successfully"); task.Dispose(); } if (task.ErrNum > 0) Environment.Exit(1); else Environment.Exit(0); }
void WriteSummary(DateTime time) { task.ListStream.WriteLine("/*"); task.ListDivider(); task.ListStream.WriteLine("NFSA Summary for input file <" + task.FileName + ">"); task.ListDivider(); task.ListStream.WriteLine("Number of Start Conditions = " + (nfas.Length - 1)); for (int i = 0; i < nfas.Length; i++) { NfsaInstance inst = nfas[i]; if (inst != null) { task.ListStream.WriteLine("Start condition " + inst.key + ":"); task.ListStream.Write(" number of patterns = " + inst.myStartCondition.rules.Count); task.ListStream.Write(", number of nfsa states = " + inst.nStates.Count); task.ListStream.WriteLine(", accept states = " + inst.acceptStates.Count); } } task.ListDivider(); task.ListStream.Write("GPLEX: NFSA built. "); task.ListStream.WriteLine(TaskState.ElapsedTime(time)); task.ListStream.Flush(); }
public NFSA(TaskState t) { task = t; }
/// <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); } }
public NFSA(TaskState t) { task = t; }
internal AAST( Automaton.TaskState t ) { task = t; startStates.Add( StartState.initState.Name, StartState.initState ); startStates.Add( StartState.allState.Name, StartState.allState ); }