Пример #1
0
        public void TestLexer2()
        {
            string path = @"..\..\..\TestSamples\code2.cpp";
            Assert.IsTrue(File.Exists(path));

            var tokens = new List<Token>();
            using( var reader = new StreamReader(path))
            {
                var lex = new Lexer(reader);
                while (!lex.EofReached)
                    tokens.Add(lex.Scan());
                Assert.AreEqual(8, Lexer.Line);
            }
            
            Assert.AreEqual(35, tokens.Count);
            Assert.IsNull(tokens[34]);// the last one is null
            var expect = new List<string> 
            { 
                "{", 
                "int", "i", ";",
                "float", "[", "100", "]", "a", ";",
                "while", "(", "true", ")",
                "{",
                "do", "i", "=", "i", "+", "1", ";",
                "while","(","a","[","i", "]", "<", "42",")",";",
                "}",
                "}"
            };
            for (int i = 0; i != tokens.Count - 1; ++i)
                Assert.AreEqual(expect[i], tokens[i].ToString());
        }
Пример #2
0
        public void TestLexer1()
        {
            string path = @"..\..\..\TestSamples\code1.cpp";
            Assert.IsTrue(File.Exists(path));
            var reader = new StreamReader(path);

            var lex = new Lexer(reader);
            var tokens = new List<Token>();
            while (!lex.EofReached)
                tokens.Add(lex.Scan());
            reader.Close();

            Assert.AreEqual(2, Lexer.Line);
            Assert.AreEqual(3, tokens.Count);
            Assert.IsNull(tokens[2]);// the last one is null
        }
Пример #3
0
 /// <summary>
 /// Recognize next token and save in _look;
 /// </summary>
 public void Move()
 {
     _look = _lexer.Scan();
 }