示例#1
0
        //
        //
        public Expression Eval(List <Token> ops)
        {
            foreach (var op in ops)
            {
                CurrentDialect.GetAction(op)(op);
            }

            //Console.ReadKey();
            //Console.WriteLine();

            if (ExprStack.Count == 0)
            {
                return(null);
            }
            //else
#if DEBUG_EXPRESSION_PARSING
            Debug.WriteLine("EvalStack Dump");
            Debug.WriteLine("----------------");
            foreach (var op in ExprStack)
            {
                Debug.Write(op.ToString());
                Debug.Write("\t\t\t");
                Debug.Write(op.NodeKind);
                Debug.Write(" : ");
                Debug.WriteLine(op.NodeKind);
            }
            Debug.WriteLine("");
#endif
            Expression expr = ExprStack.Pop();
            return(expr);
        }
示例#2
0
 //
 void ParseLine()
 {
     while (CurrentToken != null)
     {
         Token       tok    = CurrentToken;
         TokenAction action = CurrentDialect.GetAction(tok);
         action(tok);
     }
 }
        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);
        }