private SExp evalUnroller(SExp param) { var f = eval_getString(param); var u = new YaneUnroller.Unroller(); var tree = u.ParseProgram(f); return string2SExp(tree.ToString()); }
/// <summary> /// 構文解析/変換のテスト /// </summary> public static void Test() { var u = new YaneUnroller.Unroller(); var test_statement = new[] { "z = x < y ? 1 : 2;", "x = 1 + 2 * 3 + ~(4 / 5);", "foreach(sq in bb_pawn) target &= abb_mask[sq];", "foreach:enum(e in XXX) x += e;", "foreach(u32 sq in abc_def ) target &= abb[sq];", "foreach(n in nsquare ) sum+=n;", "unroll case { case 1: x++; case 2: y++; case 4: z++; }", "unroll case { case AA: x++; case BB: y++; case CC: z++; }", "switch (x) { case 3..7: xxx; }", "avoid \"case 4 : … case 8 :\"switch(xxx) { case 3..10 : AAA; }", "avoid \"case 4 : … case 8 : … break ;\" switch(xxx) { case 3: case 4 : break; case 8: AAA; break; case 9: AAA; }" , "{ closure AAA(BBB) { CCC; BBB; } AAA { DDD; } }", "unroll foreach XXX in 0,3,6..10,ABC { abcd[XXX]++; }", "for(int i=0;i<10;++i) printf(\"abc\");", "while(true) { println(); break; }", }; var test_program = new[] { "void test(int x,int y,Move* move){ printf(\"abc\"); }", "int x = 123;", "int a[] = { 1,2,3};" }; foreach (var p in test_statement) { Console.WriteLine("original → " + p); var tree = u.ParseStatement(p); Console.WriteLine(tree.ToTreeString()); Console.WriteLine(tree.ToString()); Console.WriteLine(); } foreach (var p in test_program) { Console.WriteLine("original → " + p); var tree = u.ParseProgram(p); Console.WriteLine(tree.ToTreeString()); Console.WriteLine(tree.ToString()); Console.WriteLine(); } }