static Expression ParseSimpleExpression(TextReader input) { SwallowWhitespace(input); if (EndOfInput(input)) { throw new SyntaxError("Premature end of expression"); } var c = (char)input.Peek(); if (char.IsLetter(c)) { return(ParseIdentifierOrMember(input)); } if (char.IsDigit(c) || c == '.') { return(ParseNumber(input)); } if (c == '-') { input.Read(); return(UnaryOperation(Operator.Lookup("negate"), ParseSimpleExpression(input))); } if (c == '(') { input.Read(); Expression e = ParseExpression(input); SwallowWhitespace(input); var c2 = (char)input.Read(); if (c2 != ')') { throw new SyntaxError("Expected ')' after parenthesized expression"); } return(e); } if (c == '"') { return(ParseString(input)); } throw new SyntaxError("Syntax error beginning at '" + c + "'"); }
static Operator ReadOperator(TextReader input) { SwallowWhitespace(input); return(Operator.Lookup(new string((char)input.Read(), 1))); }
static int NextOperatorPrecedence(TextReader input) { return(Operator.Lookup(PeekOperator(input)).Precedence); }