Esempio n. 1
0
        // Atom         : Value | LParen Expression RParen
        internal static INode Produce(TokenBuffer tokens)
        {
            var value = Value.Produce(tokens);
            if (value != null)
                return value;

            // HACK
            if (tokens.Current is LeftParenthesis)
                tokens.SavePosition();

            var lParen = tokens.GetTerminal<LeftParenthesis>();
            if (lParen == null)
                return null;

            var expression = Expression.Produce(tokens);
            if (expression == null)
            {
                tokens.RestorePosition();
                return null;
            }

            var rParen = tokens.GetTerminal<RightParenthesis>();
            if (rParen == null)
            {
                throw new ParseException("Missing closing parenthesis");
            }

            return expression;
        }
Esempio n. 2
0
        // ExpRoot (MulDivOp ExpRoot)*
        internal static INode Produce(TokenBuffer tokens)
        {
            var expRoot = ExpRoot.Produce(tokens);
            if (expRoot == null)
                return null;

            tokens.SavePosition();

            return BuildSubNodes(expRoot, tokens);
        }
Esempio n. 3
0
        // AddSub       : MulDiv (AddSubOp MulDiv)*
        internal static INode Produce(TokenBuffer tokens)
        {
            var mulDiv = MulDiv.Produce(tokens);
            if (mulDiv == null)
                return null;

            tokens.SavePosition();

            return BuildSubNodes(mulDiv, tokens);
        }
Esempio n. 4
0
        // ExpRoot      : Unary ExpRootOp ExpRoot | Unary
        internal static INode Produce(TokenBuffer tokens)
        {
            var unary = Unary.Produce(tokens);
            if (unary == null)
                return null;

            tokens.SavePosition();
            var expRootOp = ExpRootOp.Produce(tokens);
            if (expRootOp == null)
                return unary;

            var rhs = ExpRoot.Produce(tokens);
            if (rhs != null)
                return new ExpRoot(unary, expRootOp, rhs);

            tokens.RestorePosition();
            return null;
        }
Esempio n. 5
0
        // Unary        : AddSubOp? Atom
        internal static INode Produce(TokenBuffer tokens)
        {
            // HACK
            if (tokens.Current is AdditionOperator || tokens.Current is SubtractionOperator)
                tokens.SavePosition();

            var op = AddSubOp.Produce(tokens);

            var atom = Atom.Produce(tokens);
            if (atom != null)
            {
                if (op != null && op.IsMinus)
                    return new Unary(op, atom);
                return atom;
            }

            tokens.RestorePosition();
            return null;
        }