示例#1
0
        public void TestSimpleParenthesisExpression()
        {
            LexicalScanner scanner = new LexicalScanner("(1*2)");

            AbstractToken token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(OpenParenthesis), token);
            Assert.IsTrue(token.GetValue().Equals("("));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Integer), token);
            Assert.IsTrue(token.GetValue().Equals("1"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Operator), token);
            Assert.IsTrue(token.GetValue().Equals("*"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Integer), token);
            Assert.IsTrue(token.GetValue().Equals("2"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(CloseParenthesis), token);
            Assert.IsTrue(token.GetValue().Equals(")"));
        }
示例#2
0
        public void TestFloat()
        {
            LexicalScanner scanner = new LexicalScanner("1.0");

            AbstractToken token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Float), token);
            Assert.IsTrue(token.GetValue().Equals("1.0"));
        }
示例#3
0
        public void TestInt()
        {
            LexicalScanner scanner = new LexicalScanner("1");

            AbstractToken token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Integer), token);
            Assert.IsTrue(token.GetValue().Equals("1"));
        }
示例#4
0
        public void TestSimpleAddSubExpression()
        {
            LexicalScanner scanner = new LexicalScanner("1+2");

            AbstractToken token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Integer), token);
            Assert.IsTrue(token.GetValue().Equals("1"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(AddSub), token);
            Assert.IsTrue(token.GetValue().Equals("+"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Integer), token);
            Assert.IsTrue(token.GetValue().Equals("2"));
        }
示例#5
0
        public ParseNode Parse()
        {
            _current = _lex.GetNextToken();
            try
            {
                Expressie();
            }
            catch (MatchException me)
            {
                Console.WriteLine(me.Message);
            }

            return(_start);
        }
示例#6
0
        public void TestPolynomialsExpression()
        {
            LexicalScanner scanner = new LexicalScanner("(5-2)*3^6+1");

            List <AbstractToken> tokens = new List <AbstractToken>();

            while (!scanner.EndOfInput)
            {
                tokens.Add(scanner.GetNextToken());
            }

            Assert.AreEqual(11, tokens.Count);
        }
示例#7
0
        public void TestPolynomialsExpression()
        {
            LexicalScanner scanner = new LexicalScanner("(5-2)*3^6+1");

            List<AbstractToken> tokens = new List<AbstractToken>();

            while (!scanner.EndOfInput)
            {
                tokens.Add(scanner.GetNextToken());
            }

            Assert.AreEqual(11, tokens.Count);
        }
示例#8
0
        public void TestSimpleParenthesisExpression()
        {
            LexicalScanner scanner = new LexicalScanner("(1*2)");

            AbstractToken token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(OpenParenthesis), token);
            Assert.IsTrue(token.GetValue().Equals("("));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Integer), token);
            Assert.IsTrue(token.GetValue().Equals("1"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Operator), token);
            Assert.IsTrue(token.GetValue().Equals("*"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Integer), token);
            Assert.IsTrue(token.GetValue().Equals("2"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(CloseParenthesis), token);
            Assert.IsTrue(token.GetValue().Equals(")"));
        }
示例#9
0
        public void TestSimpleAddSubExpression()
        {
            LexicalScanner scanner = new LexicalScanner("1+2");

            AbstractToken token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Integer), token);
            Assert.IsTrue(token.GetValue().Equals("1"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(AddSub), token);
            Assert.IsTrue(token.GetValue().Equals("+"));

            token = scanner.GetNextToken();

            Assert.IsInstanceOf(typeof(Integer), token);
            Assert.IsTrue(token.GetValue().Equals("2"));
        }