// Get the ExpressionType for an operator private ExpressionType GetOpType(KeywordToken keyword) { if (keyword == KeywordToken.Add) { return(ExpressionType.Add); } if (keyword == KeywordToken.Substract) { return(ExpressionType.Subtract); } if (keyword == KeywordToken.Muliply) { return(ExpressionType.Multiply); } if (keyword == KeywordToken.Divide) { return(ExpressionType.Divide); } if (keyword == KeywordToken.Equal) { return(ExpressionType.Equal); } if (keyword == KeywordToken.NotEqual) { return(ExpressionType.NotEqual); } if (keyword == KeywordToken.GreaterThan) { return(ExpressionType.GreaterThan); } if (keyword == KeywordToken.LessThan) { return(ExpressionType.LessThan); } if (keyword == KeywordToken.And) { return(ExpressionType.And); } if (keyword == KeywordToken.Or) { return(ExpressionType.Or); } if (keyword == KeywordToken.Not) { return(ExpressionType.Not); } throw new SymplParseException( "Unrecognized keyword for operators"); }
// This parses a BinaryOp expression. // private SymplBinaryExpr ParseExprTreeBinaryOp(Lexer lexr) { KeywordToken keyword = lexr.GetToken() as KeywordToken; if (keyword == null) { throw new SymplParseException( "Internal error: parsing Binary?"); } SymplExpr left, right; ParseBinaryRuntimeCall(lexr, out left, out right); var op = GetOpType(keyword); return(new SymplBinaryExpr(left, right, op)); }
// Keep whatever casing we found in the source program so that when the // IDs are used a member names and metadata on binders, then if some MO // doesn't respect the IgnoreCase flag, there's an out for still binding. // private IdOrKeywordToken MakeIdOrKeywordToken(string name, bool quotedId) { if (!quotedId && KeywordToken.IsKeywordName(name)) { return(KeywordToken.GetKeywordToken(name)); } else { if (name.ToLower() == "let") { System.Console.WriteLine(); System.Console.WriteLine( "WARNING: using 'let'? You probably meant let*."); System.Console.WriteLine(); } return(new IdOrKeywordToken(name)); } }
// This parses a UnaryOp expression. // private SymplUnaryExpr ParseExprTreeUnaryOp(Lexer lexr) { KeywordToken keyword = lexr.GetToken() as KeywordToken; if (keyword == null) { throw new SymplParseException( "Internal error: parsing Unary?"); } var op = GetOpType(keyword); var operand = ParseExprAux(lexr); if (lexr.GetToken() != SyntaxToken.CloseParen) { throw new SymplParseException( "Unary expression missing close paren."); } return(new SymplUnaryExpr(operand, op)); }