Ejemplo n.º 1
0
        public void TestMethod3()
        {
            Lexer.Lexer lexer = new Lexer.Lexer();

            lexer.AddDefinition(new TokenDefinition {
                Regex = new Regex("[Aa][Dd][Dd]"), Type = TokenTyp.Add
            });
            lexer.AddDefinition(new TokenDefinition {
                Regex = new Regex("\\("), Type = TokenTyp.OpenParenthesis
            });
            lexer.AddDefinition(new TokenDefinition {
                Regex = new Regex("\\)"), Type = TokenTyp.CloseParenthesis
            });
            lexer.AddDefinition(new TokenDefinition {
                Regex = new Regex(","), Type = TokenTyp.Comma
            });
            lexer.AddDefinition(new TokenDefinition {
                Regex = new Regex(@"\d+"), Type = TokenTyp.Number
            });
            lexer.AddDefinition(new TokenDefinition {
                Regex = new Regex(@"\s+"), Type = TokenTyp.Whitespace, IsIgnored = true
            });

            LanguageParser parser = new LanguageParser();
            int            res    = parser.Parse(lexer.Tokenize("ADD(ADD(1,ADD(1,3)) ,ADD(1,5)").ToList());

            Assert.AreEqual(res, 11);
        }