source.h

00001 /***************************************************************
00002  *
00003  * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
00004  * University of Wisconsin-Madison, WI.
00005  * 
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you
00007  * may not use this file except in compliance with the License.  You may
00008  * obtain a copy of the License at
00009  * 
00010  *    http://www.apache.org/licenses/LICENSE-2.0
00011  * 
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  *
00018  ***************************************************************/
00019 
00020 
00021 #ifndef __CLASSAD_SOURCE_H__
00022 #define __CLASSAD_SOURCE_H__
00023 
00024 #include <vector>
00025 #include <iosfwd>
00026 #include "classad/lexer.h"
00027 
00028 BEGIN_NAMESPACE( classad )
00029 
00030 class ClassAd;
00031 class ExprTree;
00032 class ExprList;
00033 class FunctionCall;
00034 
00037 class ClassAdParser
00038 {
00039     public:
00041         ClassAdParser();
00042 
00044         ~ClassAdParser();
00045 
00055         ClassAd *ParseClassAd(const std::string &buffer, bool full=false);
00056         ClassAd *ParseClassAd(const std::string &buffer, int &offset);
00057         ClassAd *ParseClassAd(const char *buffer, bool full=false);
00058         ClassAd *ParseClassAd(const char *buffer, int &offset);
00059         ClassAd *ParseClassAd(FILE *file, bool full=false);
00060         ClassAd *ParseClassAd(std::istream &stream, bool full=false);
00061 
00062         ClassAd *ParseClassAd(LexerSource *lexer_source, bool full=false);
00063 
00073         bool ParseClassAd(const std::string &buffer, ClassAd &ad, bool full=false);
00074         bool ParseClassAd(const std::string &buffer, ClassAd &classad, int &offset);
00075         bool ParseClassAd(const char *buffer, ClassAd &classad, bool full=false);
00076         bool ParseClassAd(const char *buffer, ClassAd &classad, int &offset);
00077         bool ParseClassAd(FILE *file, ClassAd &classad, bool full=false);
00078         bool ParseClassAd(std::istream &stream, ClassAd &classad, bool full=false);
00079 
00080         bool ParseClassAd(LexerSource *lexer_source, ClassAd &ad, bool full=false);
00081 
00091         bool ParseExpression( const std::string &buffer, ExprTree*& expr, 
00092                     bool full=false);
00093 
00094         bool ParseExpression( LexerSource *lexer_source, ExprTree*& expr, 
00095                     bool full=false);
00096 
00106         ExprTree *ParseExpression( const std::string &buffer, bool full=false);
00107 
00108         ExprTree *ParseExpression( LexerSource *lexer_source, bool full=false);
00109 
00110         ExprTree *ParseNextExpression(void);
00111 
00112         void SetDebug( bool d ) { lexer.SetDebug( d ); }
00113 
00114         Lexer::TokenType PeekToken(void);
00115         Lexer::TokenType ConsumeToken(void);
00116 
00117     private:
00118         // lexical analyser for parser
00119         Lexer   lexer;
00120 
00121         // mutually recursive parsing functions
00122         bool parseExpression( ExprTree*&, bool=false);
00123         bool parseClassAd( ClassAd&, bool=false);
00124         bool parseExprList( ExprList*&, bool=false);
00125         bool parseLogicalORExpression( ExprTree*& );
00126         bool parseLogicalANDExpression( ExprTree*& );
00127         bool parseInclusiveORExpression( ExprTree*& );
00128         bool parseExclusiveORExpression( ExprTree*& );
00129         bool parseANDExpression( ExprTree*& );
00130         bool parseEqualityExpression( ExprTree*& );
00131         bool parseRelationalExpression( ExprTree*& );
00132         bool parseShiftExpression( ExprTree*& );
00133         bool parseAdditiveExpression( ExprTree*& );
00134         bool parseMultiplicativeExpression( ExprTree*& );
00135         bool parseUnaryExpression( ExprTree*& );
00136         bool parsePostfixExpression( ExprTree*& );
00137         bool parsePrimaryExpression( ExprTree*& );
00138         bool parseArgumentList( std::vector<ExprTree*>& );
00139 
00140         bool shouldEvaluateAtParseTime(const std::string &functionName,
00141                 std::vector<ExprTree*> &argList);
00142         ExprTree *evaluateFunction(const std::string &functionName,
00143                 std::vector<ExprTree*> &argList);
00144 
00145 };
00146 
00147 std::istream & operator>>(std::istream &stream, ClassAd &ad);
00148 
00149 END_NAMESPACE // classad
00150 
00151 #endif//__CLASSAD_SOURCE_H__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends