コード例 #1
0
 private void ParseUnary()
 {
     // We only have '+' and '-' as unary operators so we don't need to check precedence and pop from stack
     if (OperatorHelper.HasUnary(tokenizer.Token))
     {
         operators.Push(tokenizer.Token);
     }
 }
コード例 #2
0
        private void ParseNumber()
        {
            output.Enqueue(new TokenNumber(tokenizer.Number));

            // Need to enqueue unary operators after a number
            while (operators.Count != 0 && OperatorHelper.HasUnary(operators.Peek()))
            {
                EnqueueOperator();
            }
        }
コード例 #3
0
        private void ParseCloseParenthesis()
        {
            // If there is no '(' on the stack we get an exception
            try {
                while (operators.Peek() != TokenType.OpenParenthesis)
                {
                    EnqueueOperator();
                }
            }
            catch (InvalidOperationException) {
                throw new SyntaxException("Missing open parenthesis");
            }

            operators.Pop(); // Pop '('

            // Need to enqueue unary operators after a pair of parenthesis
            while (operators.Count != 0 && OperatorHelper.HasUnary(operators.Peek()))
            {
                EnqueueOperator();
            }
        }