コード例 #1
0
        void ShuntExpression()
        {
            ParseOperand();
            //
            while (ShuntStack.Count != 0)
            {
                Token op = ShuntStack.Pop();
                if (op.Kind != TokenKind.LeftRound)
                {
                    ShuntQueue.Add(op);
                }
            }
            while (ShuntStack2.Count != 0)
            {
                Token op = ShuntStack2.Pop();
                ShuntQueue.Add(op);
            }
#if DEBUG_EXPRESSION_PARSING
            Debug.WriteLine("ShuntQueue Dump");
            Debug.WriteLine("----------------");
            foreach (var op in ShuntQueue)
            {
                Debug.Write(op.ToString());
                Debug.Write("\t\t\t");
                Debug.Write(op.Kind);
                Debug.Write(" : ");
                Debug.WriteLine(op.Kind);
            }
            Debug.WriteLine("");
#endif
        }
コード例 #2
0
        void PushOperator(Token op)
        {
            /*if (op.IsNil)
             *  System.Diagnostics.Debugger.Break();*/

            if (op.Kind == TokenKind.LeftRound)
            {
                ShuntStack.Push(op);
                return;
            }
            if (CurrentState.ParseFlags.HasFlag(ParseFlag.ParsingClause))
            {
                if (op.IsProperty || op.IsOperator)
                {
                    bool popParen = false;
                    while (ShuntStack.Count != 0)
                    {
                        Token op2 = ShuntStack.Peek();
                        if (op2.Kind == TokenKind.LeftRound)
                        {
                            break;
                        }
                        //else
                        ShuntStack.Pop();
                        ShuntQueue.Add(op2);
                    }
                    if (popParen && op.Kind != TokenKind.Property)
                    {
                        ShuntStack.Pop();
                        CurrentState.ParseFlags &= ~ParseFlag.ParsingClause;
                    }
                }
            }
            while (ShuntStack.Count != 0)
            {
                int   p   = CurrentDialect.GetPrec(op);
                int   a   = CurrentDialect.GetAssoc(op);
                Token op2 = ShuntStack.Peek();
                int   p2  = CurrentDialect.GetPrec(op2);
                int   a2  = CurrentDialect.GetAssoc(op2);
                if ((a == 0 && p >= p2) || (p > p2))
                {
                    ShuntStack.Pop();
                    ShuntQueue.Add(op2);
                }
                else
                {
                    break;
                }
            }
            ShuntStack.Push(op);
        }