Ejemplo n.º 1
0
        /// <summary>
        /// Takes a fixed token from the queue, throws an exception if it can't.
        /// </summary>
        /// <param name="tokens">The token queue</param>
        /// <param name="kind">The kind of token to dequeue</param>
        /// <exception cref="UnexpectedTokenException">Thrown when the given token kind is not first in the queue</exception>
        private void TakeFixedToken(FixedToken.Kind kind)
        {
            var typeToken = tokens.Dequeue() as FixedToken;

            if (typeToken == null || typeToken.TokenKind != kind)
            {
                throw new UnexpectedTokenException("Did not get token of kind " + kind.ToString(), typeToken);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Peeks the next token in the queue and checks if it's a fixed token of the given kind.
        /// </summary>
        /// <param name="tokens"></param>
        /// <param name="kind"></param>
        /// <returns></returns>
        private bool PeekFixedToken(FixedToken.Kind kind)
        {
            var typeToken = tokens.Peek() as FixedToken;

            if (typeToken == null || typeToken.TokenKind != kind)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tries to take a fixed token from the queue and returns if it could. Does not change the queue if the given token kind is not on top.
        /// </summary>
        /// <param name="tokens">Queue of tokens</param>
        /// <param name="kind">The kind of token we want to dequeue</param>
        /// <returns>True if the token was dequeued, false if it wasn't</returns>
        private bool TryTakeFixedToken(FixedToken.Kind kind)
        {
            var typeToken = tokens.Peek() as FixedToken;

            if (typeToken == null || typeToken.TokenKind != kind)
            {
                return(false);
            }
            tokens.Dequeue();
            return(true);
        }
Ejemplo n.º 4
0
        public BinaryNode(FixedToken.Kind op, ExpressionNode firstTerm, ExpressionNode secondTerm)
        {
            switch (op)
            {
            case FixedToken.Kind.Add:
                Op = Operation.Add; break;

            case FixedToken.Kind.Negate:
                Op = Operation.Subtract; break;

            case FixedToken.Kind.Multiply:
                Op = Operation.Multiply; break;

            case FixedToken.Kind.Divide:
                Op = Operation.Divide; break;

            case FixedToken.Kind.LogicAnd:
                Op = Operation.LogicAnd; break;

            case FixedToken.Kind.LogicOr:
                Op = Operation.LogicOr; break;

            case FixedToken.Kind.Equal:
                Op = Operation.Equal; break;

            case FixedToken.Kind.NotEqual:
                Op = Operation.NotEqual; break;

            case FixedToken.Kind.LessThan:
                Op = Operation.LessThan; break;

            case FixedToken.Kind.LessThanOrEqual:
                Op = Operation.LessThanOrEqual; break;

            case FixedToken.Kind.GreaterThan:
                Op = Operation.GreaterThan; break;

            case FixedToken.Kind.GreaterThanOrEqual:
                Op = Operation.GreaterThanOrEqual; break;

            case FixedToken.Kind.Modulo:
                Op = Operation.Modulo; break;

            default:
                throw new ArgumentException("Token kind is not one for Binary operators!");
            }
            FirstTerm  = firstTerm;
            SecondTerm = secondTerm;
        }
Ejemplo n.º 5
0
        public UnaryNode(FixedToken.Kind op, ExpressionNode expression)
        {
            switch (op)
            {
            case FixedToken.Kind.Negate:
                Op = Operation.Negate; break;

            case FixedToken.Kind.Complement:
                Op = Operation.Complement; break;

            case FixedToken.Kind.LogicNegate:
                Op = Operation.LogicNegate; break;

            case FixedToken.Kind.Multiply:
                Op = Operation.Indirection; break;

            case FixedToken.Kind.BinaryAnd:
                Op = Operation.Address; break;

            default:
                throw new ArgumentException("Token kind is not one for Unary operators!");
            }
            Expression = expression;
        }