#include <BaseParser.h>
Inheritance diagram for BaseParser:
Public Member Functions | |
BaseParser () | |
virtual | ~BaseParser () |
virtual void | preprocessor (std::string &val) |
virtual void | error (const std::string &str) |
Protected Member Functions | |
int | ReadLine (FILE *fil) |
int | GetToken (FILE *fil, std::string &val) |
int | GetWord (const std::string &str) |
std::string | GetFilename () |
int | GetLine () |
int | GetPos () |
void | EndToken (char) |
Protected Attributes | |
int | m_level |
int | m_plevel |
int | m_glevel |
Private Types | |
typedef std::map< std::string, int > | stringint_m |
Private Attributes | |
stringint_m | m_word |
std::string | m_filename |
int | m_line |
int | m_pos |
char | the_str [5000] |
int | the_ptr |
|
Definition at line 71 of file BaseParser.h. |
|
Definition at line 36 of file BaseParser.cpp. References Class, Const, Enum, Friend, m_word, Namespace, Private, Protected, Public, Struct, Template, the_str, Typedef, Using, and Virtual.
00037 :m_level(0) 00038 ,m_plevel(0) 00039 ,m_glevel(0) 00040 ,m_filename("") 00041 ,m_line(0) 00042 ,m_pos(0) 00043 ,the_ptr(0) 00044 { 00045 *the_str = 0; 00046 00047 m_word["class"] = Class; 00048 m_word["namespace"] = Namespace; 00049 m_word["using"] = Using; 00050 m_word["template"] = Template; 00051 m_word["friend"] = Friend; 00052 m_word["typedef"] = Typedef; 00053 m_word["virtual"] = Virtual; 00054 m_word["public"] = Public; 00055 m_word["protected"] = Protected; 00056 m_word["private"] = Private; 00057 m_word["const"] = Const; 00058 m_word["struct"] = Struct; 00059 m_word["enum"] = Enum; 00060 } |
|
Definition at line 63 of file BaseParser.cpp.
00064 { 00065 } |
|
Definition at line 319 of file BaseParser.cpp. References m_glevel, m_level, and m_plevel. Referenced by SimpleParser::Parser(), and MyParser::Parser().
|
|
Reimplemented in SimpleParser. Definition at line 313 of file BaseParser.cpp. Referenced by GetToken().
|
|
Definition at line 84 of file BaseParser.h. References m_filename. Referenced by MyParser::AddToken().
00084 { return m_filename; } |
|
Definition at line 85 of file BaseParser.h. References m_line. Referenced by MyParser::AddToken().
00085 { return m_line; } |
|
Definition at line 86 of file BaseParser.h. References m_pos. Referenced by MyParser::AddToken().
00086 { return m_pos; } |
|
Definition at line 133 of file BaseParser.cpp. References AND, C1, C2, CC, CHAR, COMMENT, CPP, dblcheck, DPTR, EQ, error(), GetWord(), GTEQ, GTGT, IDENTIFIER, LTEQ, LTLT, m_glevel, m_level, m_plevel, m_pos, MM, NEQ, NUMBER, OR, POINTER, PP, ReadLine(), STRING, the_ptr, the_str, and WHITESPACE. Referenced by MyParser::Parser().
00134 { 00135 bool bWhitespace = false; 00136 while (C == ' ' || C == '\t') 00137 { 00138 bWhitespace = true; 00139 the_ptr++; 00140 } 00141 while (!C) 00142 { 00143 if (!ReadLine(fil)) 00144 return 0; 00145 if (C == '#') 00146 { 00147 val = the_str; 00148 C = 0; 00149 return CPP; 00150 } 00151 while (C == ' ' || C == '\t') 00152 { 00153 the_ptr++; 00154 } 00155 bWhitespace = true; // new line automatically adds a whitespace token 00156 } 00157 if (bWhitespace) 00158 { 00159 val = " "; 00160 return WHITESPACE; 00161 } 00162 m_pos = the_ptr; // where this token begins 00163 if (isdigit(C)) 00164 { 00165 while (isdigit(C) || C == '.') 00166 { 00167 val += C; 00168 the_ptr++; 00169 } 00170 return NUMBER; 00171 } 00172 if (isalpha(C) || C == '_' || C == '~' || (C == ':' && C1 == ':' && (isalpha(C2) || C2 == '_')) ) 00173 { 00174 if (C == '~') 00175 { 00176 val += C; 00177 the_ptr++; 00178 } 00179 while (isalnum(C) || C == '_' || (C == ':' && C1 == ':')) 00180 { 00181 if (C == ':' && C1 == ':') 00182 { 00183 val += C; 00184 the_ptr++; 00185 } 00186 val += C; 00187 the_ptr++; 00188 } 00189 { 00190 int id = GetWord(val); 00191 if (id >= 256) 00192 { 00193 return id; 00194 } 00195 } 00196 return IDENTIFIER; 00197 } 00198 if (C == '/' && C1 == '*') 00199 { 00200 while (C != '*' || C1 != '/') 00201 { 00202 val += C; 00203 the_ptr++; 00204 while (!C) 00205 { 00206 if (!ReadLine(fil)) 00207 return 0; 00208 val += '\n'; 00209 } 00210 } 00211 val += C; 00212 the_ptr++; 00213 val += C; 00214 the_ptr++; 00215 val += '\n'; 00216 return COMMENT; 00217 } 00218 if (C == '/' && C1 == '/') 00219 { 00220 val = (char *)(the_str + the_ptr); 00221 C = 0; 00222 val += '\n'; 00223 return COMMENT; 00224 } 00225 if (C == 34) 00226 { 00227 val += C; 00228 the_ptr++; 00229 while (C != 34 && C) 00230 { 00231 if (C == '\\') // escaping 00232 { 00233 val += C; 00234 the_ptr++; 00235 } 00236 val += C; 00237 the_ptr++; 00238 } 00239 if (C == 34) 00240 { 00241 val += C; 00242 the_ptr++; 00243 } 00244 else 00245 { 00246 error("Unterminated string constant"); 00247 } 00248 return STRING; 00249 } 00250 if (C == '\'') 00251 { 00252 val += C; 00253 the_ptr++; 00254 while (C != '\'' && C) 00255 { 00256 if (C == '\\') // escaping 00257 { 00258 val += C; 00259 the_ptr++; 00260 } 00261 val += C; 00262 the_ptr++; 00263 } 00264 if (C == '\'') 00265 { 00266 val += C; 00267 the_ptr++; 00268 } 00269 else 00270 { 00271 error("Unterminated char constant"); 00272 } 00273 return CHAR; 00274 } 00275 // dbl chars 00276 #define dblcheck(x1,x2,y) { \ 00277 if (C == x1 && C1 == x2) \ 00278 { \ 00279 val = x1; \ 00280 val += x2; \ 00281 the_ptr += 2; \ 00282 return y; \ 00283 } \ 00284 } 00285 // 00286 dblcheck(':',':',CC); 00287 dblcheck('<','<',LTLT); 00288 dblcheck('>','>',GTGT); 00289 dblcheck('*','*',DPTR); 00290 dblcheck('<','=',LTEQ); 00291 dblcheck('!','=',NEQ); 00292 dblcheck('>','=',GTEQ); 00293 dblcheck('=','=',EQ); 00294 dblcheck('|','|',OR); 00295 dblcheck('&','&',AND); 00296 dblcheck('+','+',PP); 00297 dblcheck('-','-',MM); 00298 dblcheck('-','>',POINTER); 00299 // single char: 00300 val += C; 00301 if (C == '{') 00302 { 00303 m_level++; 00304 } 00305 if (C == '(') 00306 m_plevel++; 00307 if (C == '<') 00308 m_glevel++; 00309 return the_str[the_ptr++]; 00310 } |
|
Definition at line 68 of file BaseParser.cpp. References m_word. Referenced by SimpleParser::GetToken(), and GetToken().
|
|
Definition at line 85 of file BaseParser.cpp. References Parse::getword(), m_filename, and m_line. Referenced by MyParser::Parser().
00086 { 00087 Parse pa( (char *)val.c_str() ); 00088 int line; 00089 char slask[200]; 00090 00091 strcpy(slask,pa.getword().c_str()); // '#' 00092 assert(*slask == '#'); 00093 if (!strcmp(slask,"#")) 00094 { 00095 strcpy(slask,pa.getword().c_str()); // line 00096 if (isdigit(*slask)) 00097 { 00098 line = atoi(slask); 00099 strcpy(slask,pa.getword().c_str()); // "filename" 00100 if (*slask == 34) 00101 { 00102 slask[strlen(slask) - 1] = 0; 00103 m_filename = (char *)(slask + 1); 00104 m_line = line; 00105 } 00106 } 00107 } 00108 } |
|
Definition at line 111 of file BaseParser.cpp. References Cx, m_line, the_ptr, and the_str. Referenced by GetToken().
00112 { 00113 fgets(the_str,500,fil); 00114 m_line++; 00115 if (feof(fil)) 00116 return 0; 00117 while (strlen(the_str) && (Cx == 13 || Cx == 10)) 00118 Cx = 0; 00119 while (Cx == '\\') // continue 00120 { 00121 fgets(the_str + strlen(the_str) - 1,500,fil); 00122 m_line++; 00123 if (feof(fil)) 00124 return 0; 00125 while (strlen(the_str) && (Cx == 13 || Cx == 10)) 00126 Cx = 0; 00127 } 00128 the_ptr = 0; 00129 return 1; 00130 } |
|
Definition at line 95 of file BaseParser.h. Referenced by GetFilename(), and preprocessor(). |
|
Definition at line 91 of file BaseParser.h. Referenced by EndToken(), and GetToken(). |
|
Definition at line 89 of file BaseParser.h. Referenced by EndToken(), and GetToken(). |
|
Reimplemented in SimpleParser. Definition at line 96 of file BaseParser.h. Referenced by error(), GetLine(), preprocessor(), and ReadLine(). |
|
Definition at line 90 of file BaseParser.h. Referenced by EndToken(), and GetToken(). |
|
Definition at line 97 of file BaseParser.h. Referenced by GetPos(), and GetToken(). |
|
Definition at line 94 of file BaseParser.h. Referenced by BaseParser(), and GetWord(). |
|
Reimplemented in SimpleParser. Definition at line 99 of file BaseParser.h. Referenced by GetToken(), and ReadLine(). |
|
Reimplemented in SimpleParser. Definition at line 98 of file BaseParser.h. Referenced by BaseParser(), GetToken(), and ReadLine(). |