Esempio n. 1
0
 private Expression UnaryExpression(ref bool isLHS)
 {
     var stack = new Seq<UnaryOperator>();
     while (true)
     {
         switch (Current.Tag)
         {
             case InputElementTag.Delete:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.Delete));
                 Consume();
                 break;
             case InputElementTag.Void:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.Void));
                 Consume();
                 break;
             case InputElementTag.Typeof:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.TypeOf));
                 Consume();
                 break;
             case InputElementTag.PlusPlus:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.PreIncrement));
                 Consume();
                 break;
             case InputElementTag.MinusMinus:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.PreDecrement));
                 Consume();
                 break;
             case InputElementTag.Plus:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.UnaryPlus));
                 Consume();
                 break;
             case InputElementTag.Minus:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.UnaryMinus));
                 Consume();
                 break;
             case InputElementTag.Twiddle:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.BitwiseNot));
                 Consume();
                 break;
             case InputElementTag.Bang:
                 stack.Push(new UnaryOperator(Current.Loc, UnaryOp.LogicalNot));
                 Consume();
                 break;
             default:
             {
                 var e = PostfixExpression(ref isLHS);
                 while (stack.Count > 0)
                 {
                     isLHS = false;
                     var op = stack.Pop();
                     e = new UnaryExpression(op.Loc.Union(e.Loc), op, e);
                 }
                 return e;
             }
         }
     }
 }
Esempio n. 2
0
 private void Reduce(ref Expression bottom, Seq<SREntry> stack)
 {
     var top = stack.Pop();
     if (stack.Count == 0)
         bottom = new BinaryExpression(bottom.Loc.Union(top.Exp.Loc), bottom, top.Op, top.Exp);
     else
         stack.Peek().Exp = new BinaryExpression(stack.Peek().Exp.Loc.Union(top.Exp.Loc), stack.Peek().Exp, top.Op, top.Exp);
 }
Esempio n. 3
0
        // According to the grammar:
        //     MemberExpression ::= (PrimaryExpression | "new" MemberExpression Arguments) ("[" Expression "]" | "." Identifier)*
        //     LeftHandSideExpression ::=
        //         "new"+ MemberExpression
        //      | MemberExpression (Arguments (Arguments | "[" Expression "]" | "." Identifier)*)?

        private Expression PopNew(Seq<InputElement> newStack, Expression constructor)
        {
            var ie = newStack.Pop();
            return new NewExpression(ie.Loc.Union(constructor.Loc), constructor);
        }