Example #1
0
        /// <summary>
        /// Главная функция. Парсит скрипт в запускаемые команды
        /// </summary>
        public static Script parseScript(string script)
        {
            LexemParser  lexemParser = new LexemParser(script);
            List <Lexem> lexems      = lexemParser.lexems;
            Lexem        lexemBlock  = new Lexem()
            {
                childs = lexems,
                kind   = LexemKind.BLOCK,
            };
            Script result = new Script();

            result.setRoot(true);
            return(parseCommandsBlock(lexemBlock, result));
        }
Example #2
0
        public void EquationStringShouldBeParsedToSummands()
        {
            //GIVEN
            ILexemParser lexemParser = new LexemParser();

            const string inputEquation = "x^2 + 3.5xy - y";

            const int expectedSummandsCount = 3;
            var       expectedSummand1      = new Summand(new[] { new Variable('x', degree: 2) });
            var       expectedSummand2      = new Summand(new[] { new Variable('x'), new Variable('y') }, coefficient: 3.5f);
            var       expectedSummand3      = new Summand(new[] { new Variable('y') }, coefficient: -1);


            // WHEN
            var resultSummands = lexemParser.Parse(inputEquation);

            // THEN
            Assert.AreEqual(resultSummands.Count, expectedSummandsCount);

            Assert.AreEqual(resultSummands[0], expectedSummand1);
            Assert.AreEqual(resultSummands[1], expectedSummand2);
            Assert.AreEqual(resultSummands[2], expectedSummand3);
        }