static void Main2() { var id = @"[A-Z_a-z][A-Z_a-z0-9]*"; var @int = @"0|(\-?[1-9][0-9]*)"; var space = @"( |\t|\r|\n|\v|\f)"; Lex.RenderOptimizedExecutionGraph(id, @"..\..\id_nfa.jpg"); Lex.RenderOptimizedExecutionGraph(@int, @"..\..\int_nfa.jpg"); Lex.RenderOptimizedExecutionGraph(@space, @"..\..\space_nfa.jpg"); var prog = Lex.CompileLexerRegex(true, id, // id @int, // int space // space ); prog = Lex.CompileRegexPart(@int); prog = Lex.FinalizePart(prog); Console.WriteLine(Lex.Disassemble(prog)); Console.WriteLine(Lex.RunWithLogging(prog, LexContext.Create("123"), Console.Out)); }
static void Test() { var test = "switch case \"a\":L0001, case \"b\":L0002, default: L0004\r\n" + "L0001: char \"b\"\r\n" + "L0002: char \"c\"\r\n" + "L0003: match 1\r\n" + "L0004: any\r\n" + "L0005: match -1\r\n"; var prog = Lex.AssembleFrom(@"..\..\int.lasm"); //Console.WriteLine(Lex.Disassemble(prog)); var lc = LexContext.Create("1000"); //Console.WriteLine("{0}: {1}",Lex.Run(prog,lc),lc.GetCapture()); // //"((\\(['\\"abfnrtv0]|[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}))|[^\\"])*" test = @"""((\\(['\\""abfnrtv0]|[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}))|[^\\""])*"""; //Lex.RenderGraph(LexContext.Create(test),@"..\..\string_nfa.jpg"); prog = Lex.CompileRegexPart(test); prog = Lex.FinalizePart(prog); Console.WriteLine(Lex.Disassemble(prog)); test = "\"\\\"\\tHello World!\\\"\""; lc = LexContext.Create(test); if (-1 != Lex.RunWithLogging(prog, lc, Console.Error)) { Console.Write("Matched " + test + ": "); Console.WriteLine(lc.GetCapture()); } else { Console.Write("Matched " + test + ": "); Console.WriteLine("False - failed at position " + lc.Position); } return; _RunLexer(); }