/// <summary> /// Returns a parsed DPL instance. /// </summary> /// <param name="reader">The TextReader value to be parsed.</param> /// <returns>A parsed Program instance.</returns> private IExpr ParseExpr(TextReader reader) { IExpr result = null; Lexer lexer = new Lexer(reader); tokens = lexer.Lex(); if (tokens.Peek().Type == TokenTypes.EQUAL) { tokens.Extract(); // skip over the equal curToken = tokens.Extract(); // set up the first token MatchExprAndOr(out result); // start with lowest precedence and work up } if (curToken.Type != TokenTypes.EOF) { throw new ParserException("End of expression expected." + " At column " + Convert.ToString(curToken.StartCol)); } return(result); }
/// <summary> /// Returns a parsed DPL instance. /// </summary> /// <param name="reader">The TextReader value to be parsed.</param> /// <returns>A parsed Program instance.</returns> private IExpr ParseExpr(TextReader reader) { IExpr result=null; Lexer lexer = new Lexer(reader); tokens = lexer.Lex(); if (tokens.Peek().Type == TokenTypes.EQUAL) { tokens.Extract(); // skip over the equal curToken = tokens.Extract(); // set up the first token MatchExprAndOr(out result); // start with lowest precedence and work up } if (curToken.Type != TokenTypes.EOF) throw new ParserException("End of expression expected." + " At column " + Convert.ToString(curToken.StartCol)); return result; }
/// <summary> /// Returns a parsed DPL instance. /// </summary> /// <param name="reader">The TextReader value to be parsed.</param> /// <returns>A parsed Program instance.</returns> private IExpr ParseExpr(TextReader reader) { IExpr result=null; Lexer lexer = new Lexer(reader); tokens = lexer.Lex(); if (tokens.Peek().Type == TokenTypes.EQUAL) { tokens.Extract(); // skip over the equal curToken = tokens.Extract(); // set up the first token MatchExprAndOr(out result); // start with lowest precedence and work up } if (curToken.Type != TokenTypes.EOF) throw new ParserException(Strings.Parser_ErrorP_EndExpressionExpected + GetLocationInfo(curToken)); return result; }
// ExprAndOr: private void MatchExprAndOr(out IExpr result) { TokenTypes t; // remember the type IExpr lhs; MatchExprNot(out lhs); result = lhs; // in case we get no matches while ((t = curToken.Type) == TokenTypes.AND || t == TokenTypes.OR) { curToken = tokens.Extract(); IExpr rhs; MatchExprNot(out rhs); bool bBool = (rhs.GetTypeCode() == TypeCode.Boolean && lhs.GetTypeCode() == TypeCode.Boolean); if (!bBool) { throw new ParserException("AND/OR operations require both sides to be boolean expressions." + " At column " + Convert.ToString(curToken.StartCol)); } switch (t) { case TokenTypes.AND: result = new FunctionAnd(lhs, rhs); break; case TokenTypes.OR: result = new FunctionOr(lhs, rhs); break; } lhs = result; // in case we have more AND/OR s } }