public void TestInterpreterCalcReal() { NakoCompiler ns = new NakoCompiler(); NakoInterpreter runner = new NakoInterpreter(); // 1 ns.source = "PRINT 2 * 1.5"; ns.Tokenize(); ns.Parse(); runner.Run(ns.WriteIL()); Assert.AreEqual("3", runner.PrintLog); // 2 runner.Reset(); ns.source = "PRINT (1 / 2) * 4"; ns.Tokenize(); ns.Parse(); runner.Run(ns.WriteIL()); Assert.AreEqual("2", runner.PrintLog); // 3 runner.Reset(); ns.source = "PRINT 4 % 3"; ns.Tokenize(); ns.Parse(); runner.Run(ns.WriteIL()); Assert.AreEqual("1", runner.PrintLog); // 4 runner.Reset(); ns.source = "PRINT 2 ^ 3"; ns.Tokenize(); ns.Parse(); runner.Run(ns.WriteIL()); Assert.AreEqual("8", runner.PrintLog); // 5 : べき乗の優先順位 runner.Reset(); ns.source = "PRINT 2 * 3 ^ 3"; ns.Tokenize(); ns.Parse(); runner.Run(ns.WriteIL()); Assert.AreEqual("54", runner.PrintLog); }
public void TestOneLine() { NakoCompiler ns = new NakoCompiler(); NakoInterpreter runner = new NakoInterpreter(); NakoILCodeList codes = null; // (1) codes = ns.WriteIL("もし、1=1ならば、PRINT 3"); runner.Run(codes); Assert.AreEqual(runner.PrintLog, "3"); // (2) runner.Reset(); codes = ns.WriteIL("もし、1=2ならば、PRINT 3、違えば、PRINT 5"); runner.Run(codes); Assert.AreEqual(runner.PrintLog, "5"); // (3) runner.Reset(); codes = ns.WriteIL("A=1,B=2。もし,A=Bならば、PRINT`NG`。違えば、PRINT`OK`"); runner.Run(codes); Assert.AreEqual(runner.PrintLog, "OK"); }
public void TestInterpreter2() { NakoCompiler ns = new NakoCompiler(); NakoInterpreter runner = new NakoInterpreter(); // 1 ns.source = "A=5; PRINT A"; ns.Tokenize(); ns.Parse(); runner.Run(ns.WriteIL()); Assert.AreEqual("5", runner.PrintLog); // 2 runner.Reset(); ns.source = "A=5; B=8; C=A+B; PRINT C"; ns.Tokenize(); ns.Parse(); runner.Run(ns.WriteIL()); Assert.AreEqual("13", runner.PrintLog); }