Exemple #1
0
        /*
         * intExpr = [ MINUS_SYMBOL ] term { addOp term }.
         */
        SyntaxTreeNode IsIntExpr()
        {
            bool minusFlag;
            SyntaxTreeNode leftTermNode = null;
            SyntaxTreeNode rightTreeNode = null;
            FilePosition position = GetInputFilePosition();

            Symbol currentSymbol = this._scanner.PeekSymbol();
            if (currentSymbol == Symbol.MINUS_SYMBOL)
            {
                this._scanner.NextSymbol();
                minusFlag = true;
            }
            else
            {
                minusFlag = false;
            }

            if (null == (leftTermNode = IsIntTerm()))
            {
                if (!minusFlag)
                    return null;
                else
                {
                    return CreateErrorNode("intTerm expected after \'-\'");
                }
            }

            if (minusFlag)
            {
                leftTermNode = new SyntaxTreeMonadicOpNode(position, Symbol.MINUS_SYMBOL, leftTermNode);
            }

            currentSymbol = this._scanner.PeekSymbol();
            while (currentSymbol == Symbol.MINUS_SYMBOL || currentSymbol == Symbol.PLUS_SYMBOL)
            {
                position = GetInputFilePosition();
                this._scanner.NextSymbol();
                if (null == (rightTreeNode = IsIntTerm()))
                {
                    return CreateErrorNode("intTerm expected after \'addOp\'");
                }
                else
                {
                    leftTermNode = new SyntaxTreeDyadicOpNode(position, currentSymbol, leftTermNode, rightTreeNode);
                    currentSymbol = this._scanner.PeekSymbol();
                }
            }

            return leftTermNode;
        }
Exemple #2
0
        /*
         * intTerm = isIntTerm { multOp intFactor }.
         */
        SyntaxTreeNode IsIntTerm()
        {
            SyntaxTreeNode leftFactorNode = null;
            SyntaxTreeNode rightFactorNode = null;

            if (null == (leftFactorNode = IsIntFactor()))
                return null;

            Symbol currentSymbol = this._scanner.PeekSymbol();
            while (currentSymbol == Symbol.TIMES_SYMBOL ||
                currentSymbol == Symbol.DIVIDE_SYMBOL ||
                currentSymbol == Symbol.MODULO_SYMBOL)
            {
                FilePosition position = GetInputFilePosition();
                this._scanner.NextSymbol();
                if (null == (rightFactorNode = IsIntFactor()))
                {
                    return CreateErrorNode("intFactor expected after \'multOp\'");
                }
                else
                {
                    leftFactorNode = new SyntaxTreeDyadicOpNode(position, currentSymbol, leftFactorNode, rightFactorNode);
                    currentSymbol = this._scanner.PeekSymbol();
                }
            }
            return leftFactorNode;
        }
Exemple #3
0
        /*
         * boolExpr = intExpr relationOp intExpr { boolOp intExpr relationOp intExpr }.
         */
        SyntaxTreeNode IsBoolExpr()
        {
            SyntaxTreeNode leftIntExprNode = null;
            SyntaxTreeNode rightIntExprNode = null;
            SyntaxTreeNode newBoolExprNode1 = null;

            if (null == (leftIntExprNode = IsIntExpr()))
            {
                return null;
            }

            Symbol currentSymbol = this._scanner.PeekSymbol();
            FilePosition position = GetInputFilePosition();
            if (!IsRelationOpSymbol(currentSymbol))
            {
                return CreateErrorNode("\'relationOp\' expected after \'intExpr\'");
            }

            this._scanner.NextSymbol();
            if (null == (rightIntExprNode = IsIntExpr()))
            {
                return CreateErrorNode("\'intExpr\' expected after \'relationOp\'");
            }

            newBoolExprNode1 = new SyntaxTreeDyadicOpNode(position, currentSymbol, leftIntExprNode, rightIntExprNode);

            Symbol currentSymbolForBoolOp = this._scanner.PeekSymbol();
            while (currentSymbolForBoolOp == Symbol.AND_SYMBOL || currentSymbolForBoolOp == Symbol.OR_SYMBOL)
            {
                position = GetInputFilePosition();
                this._scanner.NextSymbol();

                if (null == (leftIntExprNode = IsIntExpr()))
                {
                    return CreateErrorNode("\'intExpr\' expected after \'boolOp\'");
                }
                currentSymbol = this._scanner.PeekSymbol();
                if (!IsRelationOpSymbol(currentSymbol))
                {
                    return CreateErrorNode("\'relationOp\' expected after \'intExpr\'");
                }
                this._scanner.NextSymbol();
                if (null == (rightIntExprNode = IsIntExpr()))
                {
                    return CreateErrorNode("\'intExpr\' expected after \'relationOp\'");
                }
                SyntaxTreeNode newBoolExprNode2 = new SyntaxTreeDyadicOpNode(position, currentSymbol, leftIntExprNode, rightIntExprNode);
                newBoolExprNode1 = new SyntaxTreeDyadicOpNode(position, currentSymbolForBoolOp, newBoolExprNode1, newBoolExprNode2);
                currentSymbolForBoolOp = this._scanner.PeekSymbol();
            }
            return newBoolExprNode1;
        }