Exemplo n.º 1
0
 public RuntimeError CreateAccessorSyntaxError( AccessorExpr e )
 {
     AccessorMemberExpr m = e as AccessorMemberExpr;
     if( m != null )
     {
         if( m.IsUnbound ) return CreateSyntaxError( e, "Undefined in scope: " + m.Name );
         return CreateSyntaxError( e, "Unknown property: " + m.Name );
     }
     if( e is AccessorIndexerExpr ) return CreateSyntaxError( e, "Indexer is not supported." );
     return CreateSyntaxError( e, "Not a function." );
 }
Exemplo n.º 2
0
 public PrePostIncDecExpr(SourceLocation location, AccessorExpr operand, bool plus, bool prefix, bool isStatement)
     : base(location, isStatement, true)
 {
     if (operand == null)
     {
         throw new ArgumentNullException("left");
     }
     Operand = operand;
     Plus    = plus;
     Prefix  = prefix;
 }
Exemplo n.º 3
0
 public AssignExpr(SourceLocation location, AccessorExpr left, Expr right)
     : base(location, right.IsStatement, true)
 {
     if (left == null)
     {
         throw new ArgumentNullException("left");
     }
     if (right == null)
     {
         throw new ArgumentNullException("right");
     }
     Left  = left;
     Right = right;
 }
Exemplo n.º 4
0
        Expr HandlePostIncDec(Expr left)
        {
            var loc = _parser.Location;
            var t   = _parser.CurrentToken;

            _parser.Forward();
            AccessorExpr a = left as AccessorExpr;

            if (a == null)
            {
                return(new SyntaxErrorExpr(loc, "invalid increment operand."));
            }
            return(new PrePostIncDecExpr(loc, a, t == JSTokenizerToken.PlusPlus, false, _parser.Match(JSTokenizerToken.SemiColon)));
        }
Exemplo n.º 5
0
        public RuntimeError CreateAccessorSyntaxError(AccessorExpr e)
        {
            AccessorMemberExpr m = e as AccessorMemberExpr;

            if (m != null)
            {
                if (m.IsUnbound)
                {
                    return(CreateSyntaxError(e, "Undefined in scope: " + m.Name));
                }
                return(CreateSyntaxError(e, "Unknown property: " + m.Name));
            }
            if (e is AccessorIndexerExpr)
            {
                return(CreateSyntaxError(e, "Indexer is not supported."));
            }
            return(CreateSyntaxError(e, "Not a function."));
        }
Exemplo n.º 6
0
        Expr HandleAssign(Expr left, bool pureAssign = false)
        {
            var          location = _parser.Location;
            AccessorExpr a        = left as AccessorExpr;

            if (a == null)
            {
                return(new SyntaxErrorExpr(location, "Invalid assignment left-hand side."));
            }
            if (pureAssign || _parser.Match(JSTokenizerToken.Assign))
            {
                return(new AssignExpr(location, a, Expression(JSTokenizer.PrecedenceLevel(JSTokenizerToken.Comma))));
            }
            JSTokenizerToken binaryTokenType = JSTokenizer.FromAssignOperatorToBinary(_parser.CurrentToken);

            _parser.Forward();
            return(new AssignExpr(location, a, new BinaryExpr(location, left, binaryTokenType, Expression(0))));
        }
Exemplo n.º 7
0
        Expr HandleAssign(AccessorExpr left, AccessorExpr leftSource, string unboundName = null)
        {
            Debug.Assert(left != null);
            var location = _parser.Location;

            if (_parser.Match(TokenizerToken.Assign))
            {
                return(new AssignExpr(location, left, Expression(2)));
            }
            if (leftSource == null)
            {
                leftSource = new AccessorMemberExpr(_parser.Location, null, unboundName, false);
            }
            TokenizerToken binaryTokenType = _parser.CurrentToken.FromAssignOperatorToBinary();

            _parser.Forward();
            return(new AssignExpr(location, left, new BinaryExpr(location, leftSource, binaryTokenType, Expression(2))));
        }
Exemplo n.º 8
0
        Expr HandleUnaryExpr()
        {
            var loc = _parser.Location;
            var t   = _parser.CurrentToken;

            _parser.Forward();
            // Unary operators are JSTokenizerToken.OpLevel14, except Minus and Plus that are classified as binary operators and are associated to OpLevel12.
            var right = Expression(JSTokenizer.PrecedenceLevel(JSTokenizerToken.OpLevel14));

            if (t == JSTokenizerToken.PlusPlus || t == JSTokenizerToken.MinusMinus)
            {
                AccessorExpr a = right as AccessorExpr;
                if (a == null)
                {
                    return(new SyntaxErrorExpr(loc, "invalid increment operand."));
                }
                return(new PrePostIncDecExpr(loc, a, t == JSTokenizerToken.PlusPlus, true, right.IsStatement));
            }
            return(new UnaryExpr(loc, t, right));
        }
Exemplo n.º 9
0
 Expr HandleLed(Expr left)
 {
     if (_parser.IsBinaryOperator || _parser.IsCompareOperator)
     {
         return(HandleBinaryExpr(left));
     }
     if (_parser.IsLogical)
     {
         return(HandleLogicalExpr(left));
     }
     if (_parser.Match(TokenizerToken.Dot))
     {
         return(HandleMember(left));
     }
     if (_parser.Match(TokenizerToken.QuestionMark))
     {
         return(HandleTernaryConditional(left));
     }
     if (_parser.Match(TokenizerToken.OpenPar))
     {
         return(HandleCallOrIndex(left, TokenizerToken.ClosePar));
     }
     if (_parser.Match(TokenizerToken.OpenSquare))
     {
         return(HandleCallOrIndex(left, TokenizerToken.CloseSquare));
     }
     if (_parser.IsAssignOperator)
     {
         AccessorExpr a = left as AccessorExpr;
         if (a == null)
         {
             return(new SyntaxErrorExpr(_parser.Location, "Invalid assignment left-hand side."));
         }
         return(HandleAssign(a, a));
     }
     if (_parser.CurrentToken == TokenizerToken.PlusPlus || _parser.CurrentToken == TokenizerToken.MinusMinus)
     {
         return(HandlePostIncDec(left));
     }
     return(new SyntaxErrorExpr(_parser.Location, "Syntax Error."));
 }