00001
00002
00003
00004
00005
00006
00007
00008 #ifndef SYSTEMPARSER_H_
00009 #define SYSTEMPARSER_H_
00010
00011 #include "Common.h"
00012 #include "QueryEngine.h"
00013 #include "SystemManager.h"
00014 #include <map>
00015 #include <string>
00016 #include <sstream>
00017 #include <vector>
00018
00019 enum Token {
00020 TOKEN_CREATE,
00021 TOKEN_DROP,
00022 TOKEN_DATABASE,
00023 TOKEN_TABLE,
00024 TOKEN_INDEX,
00025 TOKEN_LOAD,
00026 TOKEN_INFO,
00027 TOKEN_PRINT,
00028 TOKEN_LPAREN,
00029 TOKEN_RPAREN,
00030 TOKEN_SEMICOLON,
00031 TOKEN_COMMA,
00032 TOKEN_NAME,
00033 TOKEN_INTEGER,
00034 TOKEN_FLOAT,
00035 TOKEN_CHAR,
00036 TOKEN_QUIT,
00037 TOKEN_OPEN,
00038 TOKEN_CLOSE,
00039 TOKEN_HELP,
00040 TOKEN_IO,
00041 TOKEN_RESET,
00042 TOKEN_SELECT,
00043 TOKEN_INSERT,
00044 TOKEN_INTO,
00045 TOKEN_DELETE,
00046 TOKEN_UPDATE,
00047 TOKEN_FROM,
00048 TOKEN_VALUES,
00049 TOKEN_WHERE,
00050 TOKEN_AND,
00051 TOKEN_SET,
00052 TOKEN_QUOTE,
00053 TOKEN_LT,
00054 TOKEN_GT,
00055 TOKEN_EQ,
00056 TOKEN_ECHO,
00057 };
00058
00062 class SystemParser {
00063
00064 public:
00068 static SystemParser* getInstance();
00069
00073 int parseInput();
00074
00078 const char* getParam(const char* param);
00079
00080 private:
00081
00082 typedef struct {
00083 Token token;
00084 std::string data;
00085 } TokenData;
00086
00087 static std::map<std::string, Token> s_keywordMap;
00088 static std::map<ReturnCode, std::string> s_codeMap;
00089
00090 std::stringstream lineStream_;
00091 SystemManager* sm_;
00092 QueryEngine* qe_;
00093 std::vector<TokenData> tokens_;
00094 bool interactive_;
00095
00096 std::map<std::string, std::string> paramMap_;
00097
00098 SystemParser();
00099 ~SystemParser();
00100
00101 bool isDelimiter(char c);
00102 bool getNextCommand();
00103 bool getNextToken(TokenData& td);
00104 void syntaxError();
00105 bool matchPattern(Token pattern[], uint length);
00106 bool parseCreateTable();
00107 bool parseCreateDatabase();
00108 bool parseCreateIndex();
00109 void checkCode(ReturnCode code);
00110 int parseAttribute(AttributeInfo& attr, int offset);
00111 bool parseDropDatabase();
00112 bool parseDropTable();
00113 bool parseDropIndex();
00114 bool parseLoad();
00115 bool parseInfo();
00116 bool parseInfoRelation();
00117 bool parseHelp();
00118 bool parsePrint();
00119 bool parseOpen();
00120 bool parseClose();
00121 bool parseIOPrint();
00122 bool parseIOReset();
00123 void dumpTokens();
00124 bool parseSelect();
00125 bool parseInsert();
00126 bool parseDelete();
00127 bool parseUpdate();
00128 bool parseSet();
00129 int parseTypedValue(TypedValue& tv, int position);
00130 bool parseRelationAttribute(TokenData& td, RelationAttribute& attribute);
00131 int parseAttributes(std::vector<RelationAttribute>& attributes, int position);
00132 int parseRelations(std::vector<std::string>& relations, int position);
00133 int parseConditions(std::vector<Condition>& relations, int position);
00134 int parseCondition(Condition& condition, int position);
00135 const char* rcToString(ReturnCode code);
00136 };
00137
00138 #endif