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 };
00057
00061 class SystemParser {
00062
00063 public:
00067 static SystemParser* getInstance();
00068
00072 int parseInput();
00073
00077 const char* getParam(const char* param);
00078
00079 private:
00080
00081 typedef struct {
00082 Token token;
00083 std::string data;
00084 } TokenData;
00085
00086 static std::map<std::string, Token> s_keywordMap;
00087 static std::map<ReturnCode, std::string> s_codeMap;
00088
00089 std::stringstream lineStream_;
00090 SystemManager* sm_;
00091 QueryEngine* qe_;
00092 std::vector<TokenData> tokens_;
00093 bool interactive_;
00094
00095 std::map<std::string, std::string> paramMap_;
00096
00097 SystemParser();
00098 ~SystemParser();
00099
00100 bool isDelimiter(char c);
00101 bool getNextCommand();
00102 bool getNextToken(TokenData& td);
00103 void syntaxError();
00104 bool matchPattern(Token pattern[], uint length);
00105 bool parseCreateTable();
00106 bool parseCreateDatabase();
00107 bool parseCreateIndex();
00108 void checkCode(ReturnCode code);
00109 int parseAttribute(AttributeInfo& attr, int offset);
00110 bool parseDropDatabase();
00111 bool parseDropTable();
00112 bool parseDropIndex();
00113 bool parseLoad();
00114 bool parseInfo();
00115 bool parseInfoRelation();
00116 bool parseHelp();
00117 bool parsePrint();
00118 bool parseOpen();
00119 bool parseClose();
00120 bool parseIOPrint();
00121 bool parseIOReset();
00122 void dumpTokens();
00123 bool parseSelect();
00124 bool parseInsert();
00125 bool parseDelete();
00126 bool parseUpdate();
00127 bool parseSet();
00128 int parseTypedValue(TypedValue& tv, int position);
00129 bool parseRelationAttribute(TokenData& td, RelationAttribute& attribute);
00130 int parseAttributes(std::vector<RelationAttribute>& attributes, int position);
00131 int parseRelations(std::vector<std::string>& relations, int position);
00132 int parseConditions(std::vector<Condition>& relations, int position);
00133 int parseCondition(Condition& condition, int position);
00134 const char* rcToString(ReturnCode code);
00135 };
00136
00137 #endif