public void ParserTest1() { Amil.Lexer lexer = Amil.Amil.AmilLexer; Amil.Parser parser = new Amil.Parser(); Amil.Statement statement = parser.parse(lexer.Lex("{var a; if 0 { print true; }")); Console.WriteLine(statement.ToString()); }
public void ParserTest2() { Amil.Lexer lexer = Amil.Amil.AmilLexer; Amil.Parser parser = new Amil.Parser(); Amil.Statement statement = parser.parse(lexer.Lex("{ print 1+2+3+4+5; }")); Console.WriteLine(statement.ToString()); }
public void VirtualMachineTest2() { Amil.Lexer lexer = Amil.Amil.AmilLexer; Amil.Parser parser = new Amil.Parser(); Amil.VirtualMachine vm = new Amil.VirtualMachine(100); vm.LoadInstructions(parser.parse(lexer.Lex("{if false { print false; } print true; }")).Compile()); vm.Execute(); }
public void TestMethod1() { Amil.Lexer lexer = Amil.Amil.AmilLexer; IEnumerable <Amil.Token> tokens = lexer.Lex("a = 1;\nif a >= 2 {\nprint hello;\n}"); /*foreach (Amil.Token token in tokens) { * Debug.WriteLine(token.Type); * Debug.WriteLine(token.Value); * }*/ List <Tuple <Amil.TokenType, string> > expectedTokenVals = new List <Tuple <Amil.TokenType, string> > { new Tuple <Amil.TokenType, string>(Amil.TokenType.NAME, "a"), new Tuple <Amil.TokenType, string>(Amil.TokenType.EQUAL, "="), new Tuple <Amil.TokenType, string>(Amil.TokenType.INTEGER, "1"), new Tuple <Amil.TokenType, string>(Amil.TokenType.SEMICOLON, ";"), new Tuple <Amil.TokenType, string>(Amil.TokenType.IF, "if"), new Tuple <Amil.TokenType, string>(Amil.TokenType.NAME, "a"), new Tuple <Amil.TokenType, string>(Amil.TokenType.GREATER_EQUAL, ">="), new Tuple <Amil.TokenType, string>(Amil.TokenType.INTEGER, "2"), new Tuple <Amil.TokenType, string>(Amil.TokenType.LBRACE, "{"), new Tuple <Amil.TokenType, string>(Amil.TokenType.PRINT, "print"), new Tuple <Amil.TokenType, string>(Amil.TokenType.NAME, "hello"), new Tuple <Amil.TokenType, string>(Amil.TokenType.SEMICOLON, ";"), new Tuple <Amil.TokenType, string>(Amil.TokenType.RBRACE, "}") }; int index = 0; foreach (Amil.Token token in tokens) { if (index < expectedTokenVals.Count) { Assert.AreEqual(expectedTokenVals[index].Item1, token.Type); Assert.AreEqual(expectedTokenVals[index].Item2, token.Value); } else { Assert.Fail("Lexer returned more tokens than expected"); } index++; } }