Esempio n. 1
0
        private ICalculatable ReduceExpression(bool isLogic = false)
        {
            Token temp;
            var   exprQ = new Queue <Token>();


            do
            {
                temp = (Token)parsingStack.Pop();
                if (temp.Type == Token_type.ASSIGN ||
                    temp.Type == Token_type.PRINT ||
                    temp.Type == Token_type.WHILE ||
                    temp.Type == Token_type.IF)
                {
                    break;                                   // getting rid of '=' sign
                }
                Console.WriteLine($"Tuda-suda {temp.Type}"); // TODO: REMOVE

                if (temp.Type == Token_type.GREATER_THAN ||
                    temp.Type == Token_type.LESS_THAN ||
                    Token_type.EQUAL == temp.Type ||
                    Token_type.NOT_EQUAL == temp.Type ||
                    temp.Type == Token_type.TRUE ||
                    temp.Type == Token_type.FALSE)
                {
                    isLogic = true;
                }

                exprQ.Enqueue(temp);
            } while (parsingStack.Count != 0);

            exprQ = new Queue <Token>(exprQ.Reverse());

            ICalculatable expr;

            if (isLogic)
            {
                expr = new LogicExpression(exprQ);
            }
            else
            {
                expr = new MathExpression(exprQ);
            }

            return(expr);
        }
Esempio n. 2
0
        private void ReduceWhile()
        {
            Token temp;

            do
            {
                temp = tokenStream.GetToken(); if (temp.Type == Token_type.OPEN_BRACKET)
                {
                    break;                                                                      // getting rid of bracket
                }
                parsingStack.Push(temp);
            } while (!tokenStream.Eof());
            LogicExpression expr = (LogicExpression)ReduceExpression(true);

            parsingStack.Push(temp); //putting  bracket back to stack so codeBlock knows when to stop
            int bracketCount = 1;    // needed to process nested blocks;

            while (bracketCount != 0 || temp.Type != Token_type.CLOSE_BRACKET)
            {
                temp = tokenStream.GetToken();

                if (temp.Type == Token_type.OPEN_BRACKET)
                {
                    bracketCount++;
                }
                else if (temp.Type == Token_type.CLOSE_BRACKET)
                {
                    bracketCount--;
                }

                parsingStack.Push(temp);
            }

            CodeBlock codeBlock = ReduceCodeBlock();


            parsingStack.Push(new WhileStatement(expr, codeBlock));
        }
Esempio n. 3
0
 public WhileStatement(LogicExpression expr, CodeBlock block)
 {
     lExpr  = expr;
     cBlock = block;
 }