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." ); }
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; }
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; }
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))); }
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.")); }
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)))); }
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)))); }
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)); }
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.")); }