Пример #1
0
        public void SetUp()
        {
            var validator       = new MathRegex();
            var expressionFixer = new ExpressionFixer(validator);

            this.lexer = new MathLexer(validator, expressionFixer);
        }
        public void TestMethod2()
        {
            MathLexer lexer = new MathLexer();

            CheckTokens(lexer.Tokenize("5"),
                        "(literal)", "5"
                        );
        }
        public void TestMethod15()
        {
            MathLexer lexer = new MathLexer();

            CheckTokens(lexer.Tokenize("1.8e+6"),
                        "(literal)", "1.8e+6"
                        );
        }
        public static MathParser GetParser(string s)
        {
            var inputStream = new AntlrInputStream(new StringReader(s));
            var lexer       = new MathLexer(inputStream);
            var tokenStream = new CommonTokenStream(lexer);

            return(new MathParser(tokenStream));
        }
        public void TestMethod6()
        {
            MathLexer lexer = new MathLexer();

            CheckTokens(lexer.Tokenize("-1"),
                        "(operator)", "-",
                        "(literal)", "1"
                        );
        }
        public void TestMethod3()
        {
            MathLexer l = new MathLexer();

            CheckTokens(l.Tokenize("-3"),
                        "(operator)", "-",
                        "(literal)", "3"
                        );
        }
Пример #7
0
 public void SetUp()
 {
     _lexer      = new MathLexer(new ExpressionFixer());
     _calculator = new Calculator();
     _calcProxy  = new CalcProxy(new Validator(-100, 100), _calculator);
     _precedence = new Precedence();
     _resolver   = new Resolver(_lexer, _calcProxy, _precedence);
     _parser     = new MathParser(_lexer, _resolver);
 }
Пример #8
0
        public void TestMethod1()
        {
            MathLexer    l      = new MathLexer();
            List <Token> tokens = new List <Token>(l.Tokenize(" 1234 "));

            Assert.AreEqual(1, tokens.Count);
            Assert.AreEqual("(literal)", tokens[0].Type);
            Assert.AreEqual("1234", tokens[0].Value);
        }
        public void TestMethod1()
        {
            MathLexer l = new MathLexer();

            CheckTokens(l.Tokenize("2 + 3"),
                        "(literal)", "2",
                        "(operator)", "+",
                        "(literal)", "3"
                        );
        }
Пример #10
0
        /// <summary>
        /// Evaluates an expression and returns a <see cref="Variable" />.
        /// </summary>
        /// <param name="expression">The expression to evaluate.</param>
        /// <param name="data">The <see cref="Data" /> object containing all of the story variables.</param>
        /// <returns>A <see cref="Variable" /> instance containing the results of the evaluation.</returns>
        private static Variable Evaluate(string expression, Data data)
        {
            var lexer   = new MathLexer(new AntlrInputStream(expression));
            var parser  = new MathParser(new CommonTokenStream(lexer));
            var visitor = new MathVisitor {
                Data = data
            };

            return(visitor.Visit(parser.expr()));
        }
        public void TestMethod10()
        {
            MathLexer lexer = new MathLexer();

            CheckTokens(lexer.Tokenize("-09/03"),
                        "(operator)", "-",
                        "(literal)", "09",
                        "(operator)", "/",
                        "(literal)", "03"
                        );
        }
Пример #12
0
 public void SetUp()
 {
     var expressionValidator = new MathRegex();
     var expressionFixer = new ExpressionFixer(expressionValidator);
     this.lexer = new MathLexer(expressionValidator, expressionFixer);
     var limitsValidator = new LimitsValidator(-100, 100);
     var proxy = new CalculatorProxy(limitsValidator);
     var calculator = new Calculator();
     var operatorFactory = new OperatorFactory(proxy, calculator);
     this.parser = new MathParser(this.lexer, operatorFactory);
 }
        public void TestMethod9()
        {
            MathLexer lexer = new MathLexer();

            CheckTokens(lexer.Tokenize("90*(-4)"),
                        "(literal)", "90",
                        "(operator)", "*",
                        "(parenthesis)", "(",
                        "(operator)", "-",
                        "(literal)", "4",
                        "(parenthesis)", ")"
                        );
        }
Пример #14
0
        public void SetUp()
        {
            var expressionValidator = new MathRegex();
            var expressionFixer     = new ExpressionFixer(expressionValidator);

            this.lexer = new MathLexer(expressionValidator, expressionFixer);
            var limitsValidator = new LimitsValidator(-100, 100);
            var proxy           = new CalculatorProxy(limitsValidator);
            var calculator      = new Calculator();
            var operatorFactory = new OperatorFactory(proxy, calculator);

            this.parser = new MathParser(this.lexer, operatorFactory);
        }
        public void TestMethod11()
        {
            MathLexer lexer = new MathLexer();

            CheckTokens(lexer.Tokenize("-09/(-03)"),
                        "(operator)", "-",
                        "(literal)", "09",
                        "(operator)", "/",
                        "(parenthesis)", "(",
                        "(operator)", "-",
                        "(literal)", "03",
                        "(parenthesis)", ")"
                        );
        }
        public void TestMethod12()
        {
            MathLexer lexer = new MathLexer();

            CheckTokens(lexer.Tokenize("10-7/(2)"),
                        "(literal)", "10",
                        "(operator)", "-",
                        "(literal)", "7",
                        "(operator)", "/",
                        "(parenthesis)", "(",
                        "(literal)", "2",
                        "(parenthesis)", ")"
                        );
        }
        public void TestMethod5()
        {
            MathLexer lexer = new MathLexer();

            CheckTokens(lexer.Tokenize("-2+(-3)"),
                        "(operator)", "-",
                        "(literal)", "2",
                        "(operator)", "+",
                        "(parenthesis)", "(",
                        "(operator)", "-",
                        "(literal)", "3",
                        "(parenthesis)", ")"
                        );
        }
        public void TestMethod13()
        {
            MathLexer lexer = new MathLexer();

            CheckTokens(lexer.Tokenize("1.2+6-(-4)"),
                        "(literal)", "1.2",
                        "(operator)", "+",
                        "(literal)", "6",
                        "(operator)", "-",
                        "(parenthesis)", "(",
                        "(operator)", "-",
                        "(literal)", "4",
                        "(parenthesis)", ")"
                        );
        }
Пример #19
0
 private void click_Click(object sender, EventArgs e)
 {
     try
     {
         LexerBox.Text = "";
         var lexer  = new MathLexer();
         var tokens = lexer.Tokenize(TextBox.Text);
         foreach (var token in tokens)
         {
             LexerBox.Text += token + "\r\n";
         }
     }
     catch
     {
         TextBox.Text = "error input";
     }
 }
Пример #20
0
 public void SetUp()
 {
     var validator = new MathRegex();
     var expressionFixer = new ExpressionFixer(validator);
     this.lexer = new MathLexer(validator, expressionFixer);
 }
Пример #21
0
 public void TestMethod2()
 {
     MathLexer    l      = new MathLexer();
     List <Token> tokens = new List <Token>(l.Tokenize("12 | 34"));
 }
Пример #22
0
 public void SetUp()
 {
     _lexer = new MathLexer(new ExpressionFixer());
 }