static void Test2() { Console.WriteLine("test2"); Compiler c = new Compiler(); string s = "let x = (+ (+ x 5) (- y z));"; Stack <Token> sTokens = c.Tokenize(s); string[] aTokens = new string[] { "let", "x", "=", "(", "+", "(", "+", "x", "5", ")", "(", "-", "y", "z", ")", ")", ";" }; for (int i = 0; i < aTokens.Length; i++) { Token sToken = sTokens.Pop(); if (sToken.ToString() != aTokens[i]) { Console.WriteLine("BUGBUG"); } } sTokens = c.Tokenize(s); AssignmentStatement assignment = c.Parse(sTokens); if (assignment.ToString() != s) { Console.WriteLine("BUGBUG"); } List <AssignmentStatement> lSimple = c.SimplifyExpressions(assignment); string[] aSimple = new string[] { "let _3 = (+ x 5);", "let _4 = (- y z);", "let x = (+ _3 _4);" }; for (int i = 0; i < aSimple.Length; i++) { if (lSimple[i].ToString() != aSimple[i]) { Console.WriteLine("BUGBUG"); } } c.Compile(s); }
static void Test1() { Console.WriteLine("test1"); Compiler c = new Compiler(); string s = "let x = 5;"; Stack <Token> sTokens = c.Tokenize(s); string[] aTokens = new string[] { "let", "x", "=", "5", ";" }; List <Token> answer = new List <Token>(); for (int i = 0; i < aTokens.Length; i++) { Token sToken = sTokens.Pop(); answer.Add(sToken); bool print = false; if (sToken.ToString() != aTokens[i]) { print = true; } if (print) { Console.WriteLine("tokens should be: " + aTokens + " but your answer is: " + answer); } } sTokens = c.Tokenize(s); AssignmentStatement assignment = c.Parse(sTokens); if (assignment.ToString() != s) { Console.WriteLine("BUGBUG"); } List <AssignmentStatement> lSimple = c.SimplifyExpressions(assignment); if (lSimple.Count != 1 || lSimple[0].ToString() != assignment.ToString()) { Console.WriteLine("BUGBUG"); } //List<string> lAssembly = c.GenerateCode(lSimple); c.Compile(s); }