Example #1
0
        /// <summary>
        /// Process the term2 rule.
        /// </summary>
        /// <remarks>
        ///
        /// term2 ::= '*' factor term2 |
        ///           '/' factor term2 |
        ///           {empty}
        ///
        /// </remarks>
        /// <returns>Parsed node.</returns>
        protected virtual EvalNode ParseTerm2()
        {
            if (Tokeniser.Next(TokenType.Multiply))
            {
                EvalNode op    = new EvalNodeBinaryOp(EvalNodeBinaryOp.BinaryOp.Multiply, ParseFactor(), Language);
                EvalNode term2 = ParseTerm2();
                if (term2 != null)
                {
                    term2.Prepend(op);
                }
                return(op);
            }

            if (Tokeniser.Next(TokenType.Divide))
            {
                EvalNode op    = new EvalNodeBinaryOp(EvalNodeBinaryOp.BinaryOp.Divide, ParseFactor(), Language);
                EvalNode term2 = ParseTerm2();
                if (term2 != null)
                {
                    term2.Prepend(op);
                }
                return(op);
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Parse the 'expression2' rule.
        /// </summary>
        /// <remarks>
        ///
        /// expression2 ::= '+' term expression2 |
        ///                 '-' term expression2 |
        ///                 {empty}
        ///
        /// </remarks>
        /// <returns>Parsed node.</returns>
        protected virtual EvalNode ParseExpression2()
        {
            if (Tokeniser.Next(TokenType.Plus))
            {
                EvalNode op    = new EvalNodeBinaryOp(EvalNodeBinaryOp.BinaryOp.Add, ParseTerm(), Language);
                EvalNode expr2 = ParseExpression2();
                if (expr2 != null)
                {
                    expr2.Prepend(op);
                }
                return(op);
            }

            if (Tokeniser.Next(TokenType.Minus))
            {
                EvalNode op    = new EvalNodeBinaryOp(EvalNodeBinaryOp.BinaryOp.Subtract, ParseTerm(), Language);
                EvalNode expr2 = ParseExpression2();
                if (expr2 != null)
                {
                    expr2.Prepend(op);
                }
                return(op);
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// Parse the 'term' rule.
        /// </summary>
        /// <remarks>
        ///
        /// term ::= factor term2
        ///
        /// </remarks>
        /// <returns>Parsed node.</returns>
        protected virtual EvalNode ParseTerm()
        {
            EvalNode factor = ParseFactor();
            EvalNode term2  = ParseTerm2();

            if (term2 != null)
            {
                term2.Prepend(factor);
                return(term2);
            }
            else
            {
                return(factor);
            }
        }
Example #4
0
        /// <summary>
        /// Parse the 'expression' rule.
        /// </summary>
        /// <remarks>
        ///
        /// expression ::= term expression2
        ///
        /// </remarks>
        /// <returns>Parsed node.</returns>
        protected virtual EvalNode ParseExpression()
        {
            EvalNode term  = ParseTerm();
            EvalNode expr2 = ParseExpression2();

            if (expr2 != null)
            {
                expr2.Prepend(term);
                return(expr2.Root);
            }
            else
            {
                return(term.Root);
            }
        }