Exemple #1
0
 Expr HandleLogicalExpr(Expr left)
 {
     _parser.Forward();
     // Right associative operators to support short-circuit (hence the -1 on the level).
     return(new BinaryExpr(_parser.PrevNonCommentLocation, left, _parser.PrevNonCommentToken, Expression(_parser.PrevNonCommentToken.PrecedenceLevel() - 1)));
 }
Exemple #2
0
 Expr HandleNud()
 {
     if (_parser.IsErrorOrEndOfInput)
     {
         return(new SyntaxErrorExpr(_parser.Location, "Error: " + _parser.ErrorCode.ToString()));
     }
     Debug.Assert(!_parser.IsErrorOrEndOfInput);
     if (_parser.IsNumber)
     {
         return(new ConstantExpr(_parser.Location, _parser.ReadDouble(), _parser.Match(TokenizerToken.SemiColon)));
     }
     if (_parser.IsString)
     {
         return(new ConstantExpr(_parser.Location, _parser.ReadString(), _parser.Match(TokenizerToken.SemiColon)));
     }
     if (_parser.IsUnaryOperatorOrPlusOrMinus)
     {
         return(HandleUnaryExpr());
     }
     if (_parser.IsIdentifier)
     {
         if (_parser.MatchIdentifier("if"))
         {
             return(HandleIf());
         }
         if (_parser.MatchIdentifier("let"))
         {
             return(HandleLet());
         }
         if (_parser.MatchIdentifier("while"))
         {
             return(HandleWhile());
         }
         if (_parser.MatchIdentifier("break"))
         {
             return(new FlowBreakingExpr(_parser.PrevNonCommentLocation, false));
         }
         if (_parser.MatchIdentifier("continue"))
         {
             return(new FlowBreakingExpr(_parser.PrevNonCommentLocation, true));
         }
         if (_parser.MatchIdentifier("return"))
         {
             return(new FlowBreakingExpr(_parser.PrevNonCommentLocation, Expression(0), false));
         }
         if (_parser.MatchIdentifier("throw"))
         {
             return(new FlowBreakingExpr(_parser.PrevNonCommentLocation, Expression(0), true));
         }
         if (_parser.MatchIdentifier("do"))
         {
             return(HandleDoWhile());
         }
         if (_parser.MatchIdentifier("foreach"))
         {
             return(HandleForeach());
         }
         if (_parser.MatchIdentifier("function"))
         {
             return(HandleFunction());
         }
         if (_parser.MatchIdentifier("try"))
         {
             return(HandleTryCatch());
         }
         if (_parser.MatchIdentifier("with"))
         {
             return(HandleWith());
         }
         return(HandleIdentifier());
     }
     if (_parser.Match(TokenizerToken.OpenCurly))
     {
         return(HandleBlock());
     }
     if (_parser.Match(TokenizerToken.OpenPar))
     {
         SourceLocation location = _parser.PrevNonCommentLocation;
         Expr           e        = Expression(0);
         if (e is SyntaxErrorExpr)
         {
             return(e);
         }
         return(_parser.Match(TokenizerToken.ClosePar) ? e : new SyntaxErrorExpr(_parser.Location, "Expected ')' opened at {0}.", location));
     }
     if (_parser.Match(TokenizerToken.SemiColon))
     {
         return(NopExpr.Statement);
     }
     return(new SyntaxErrorExpr(_parser.Location, "Syntax Error."));
 }
Exemple #3
0
 Expr HandleBinaryExpr(Expr left)
 {
     _parser.Forward();
     return(new BinaryExpr(_parser.PrevNonCommentLocation, left, _parser.PrevNonCommentToken, Expression(_parser.PrevNonCommentToken.PrecedenceLevel())));
 }