00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _token_h
00037 #define _token_h
00038
00039 #include "types.h"
00040
00041 class Program;
00042 class HashTable;
00043 class Ptree;
00044
00045
00046
00047 class Token {
00048 public:
00049 bool Eq(char c) { return(*ptr == c && len == 1); }
00050
00051 public:
00052 char* ptr;
00053 int len;
00054 int kind;
00055 };
00056
00057
00058
00059 class Lex : public Object {
00060 public:
00061 Lex(Program*);
00062 int GetToken(Token&);
00063 int LookAhead(int);
00064 int LookAhead(int, Token&);
00065
00066 char* Save();
00067 void Restore(char*);
00068 void GetOnlyClosingBracket(Token&);
00069
00070 Ptree* GetComments();
00071 Ptree* GetComments2();
00072
00073 uint LineNumber(char*, char*&, int&);
00074
00075 static bool RecordKeyword(char*, int);
00076 static bool Reify(Ptree*, unsigned int&);
00077 static bool Reify(Ptree* t, char*&);
00078
00079 private:
00080 class TokenFifo {
00081 public:
00082 TokenFifo(Lex*);
00083 ~TokenFifo();
00084 void Clear();
00085 void Push(int, char*, int);
00086 int Pop(char*&, int&);
00087 int Peek(int);
00088 int Peek(int, char*&, int&);
00089 private:
00090 int Peek2(int);
00091 Lex* lex;
00092 int head;
00093 int tail;
00094 int size;
00095 struct Slot {
00096 int token;
00097 char* pos;
00098 int len;
00099 }* ring;
00100 };
00101
00102 friend class TokenFifo;
00103
00104 uint Tokenp() { return tokenp; }
00105 int TokenLen() { return token_len; }
00106 char* TokenPosition();
00107 char Ref(uint i);
00108 void Rewind(char*);
00109
00110 int ReadToken(char*&, int&);
00111 void SkipAttributeToken();
00112 int SkipExtensionToken(char*&, int&);
00113
00114 #if defined(_MSC_VER) || defined(_PARSE_VCC)
00115 void SkipAsmToken();
00116 void SkipDeclspecToken();
00117 #endif
00118
00119 char GetNextNonWhiteChar();
00120 int ReadLine();
00121 bool ReadCharConst(uint top);
00122 bool ReadStrConst(uint top);
00123 int ReadNumber(char c, uint top);
00124 int ReadFloat(uint top);
00125 bool ReadLineDirective();
00126 int ReadIdentifier(uint top);
00127 int Screening(char *identifier, int len);
00128 int ReadSeparator(char c, uint top);
00129 int SingleCharOp(unsigned char c);
00130 int ReadComment(char c, uint top);
00131
00132 private:
00133 Program* file;
00134 TokenFifo fifo;
00135 uint tokenp;
00136 int token_len;
00137 int last_token;
00138
00139 static HashTable* user_keywords;
00140 static Ptree* comments;
00141 };
00142
00143
00144
00145 inline bool is_blank(char c){
00146 return(c == ' ' || c == '\t' || c == '\f' || c == '\r');
00147 }
00148
00149 inline bool is_letter(char c){
00150 return('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '_'
00151 || c == '$');
00152 }
00153
00154 inline bool is_digit(char c){ return('0' <= c && c <= '9'); }
00155
00156 inline bool is_xletter(char c){ return(c == 'X' || c == 'x'); }
00157
00158 inline bool is_eletter(char c){ return(c == 'E' || c == 'e'); }
00159
00160 inline bool is_hexdigit(char c){
00161 return(is_digit(c) || 'A' <= c && c <= 'F' || 'a' <= c && c <= 'f');
00162 }
00163
00164 inline bool is_int_suffix(char c){
00165 return(c == 'U' || c == 'u' || c == 'L' || c == 'l');
00166 }
00167
00168 inline bool is_float_suffix(char c){
00169 return(c == 'F' || c == 'f' || c == 'L' || c == 'l');
00170 }
00171
00172
00173
00174 #define Identifier 258
00175 #define Constant 262
00176 #define CharConst 263
00177 #define StringL 264
00178 #define AssignOp 267
00179 #define EqualOp 268
00180 #define RelOp 269
00181 #define ShiftOp 270
00182 #define LogOrOp 271
00183 #define LogAndOp 272
00184 #define IncOp 273
00185 #define Scope 274
00186 #define Ellipsis 275
00187 #define PmOp 276
00188 #define ArrowOp 277
00189 #define BadToken 278
00190 #define AUTO 281
00191 #define CHAR 282
00192 #define CLASS 283
00193 #define CONST 284
00194 #define DELETE 285
00195 #define DOUBLE 286
00196 #define ENUM 287
00197 #define EXTERN 288
00198 #define FLOAT 289
00199 #define FRIEND 290
00200 #define INLINE 291
00201 #define INT 292
00202 #define LONG 293
00203 #define NEW 294
00204 #define OPERATOR 295
00205 #define PRIVATE 296
00206 #define PROTECTED 297
00207 #define PUBLIC 298
00208 #define REGISTER 299
00209 #define SHORT 300
00210 #define SIGNED 301
00211 #define STATIC 302
00212 #define STRUCT 303
00213 #define TYPEDEF 304
00214 #define UNION 305
00215 #define UNSIGNED 306
00216 #define VIRTUAL 307
00217 #define VOID 308
00218 #define VOLATILE 309
00219 #define TEMPLATE 310
00220 #define MUTABLE 311
00221 #define BREAK 312
00222 #define CASE 313
00223 #define CONTINUE 314
00224 #define DEFAULT 315
00225 #define DO 316
00226 #define ELSE 317
00227 #define FOR 318
00228 #define GOTO 319
00229 #define IF 320
00230 #define RETURN 321
00231 #define SIZEOF 322
00232 #define SWITCH 323
00233 #define THIS 324
00234 #define WHILE 325
00235 #define ATTRIBUTE 326 // g++
00236 #define METACLASS 327
00237 #define UserKeyword 328
00238 #define UserKeyword2 329
00239 #define UserKeyword3 330
00240 #define UserKeyword4 331
00241 #define BOOLEAN 332
00242 #define EXTENSION 333 // g++
00243 #define TRY 334
00244 #define CATCH 335
00245 #define THROW 336
00246 #define UserKeyword5 337
00247 #define NAMESPACE 338
00248 #define USING 339
00249
00250
00251
00252 #define ntDeclarator 400
00253 #define ntName 401
00254 #define ntFstyleCast 402
00255 #define ntClassSpec 403
00256 #define ntEnumSpec 404
00257 #define ntDeclaration 405
00258 #define ntTypedef 406
00259 #define ntTemplateDecl 407
00260 #define ntMetaclassDecl 408
00261 #define ntLinkageSpec 409
00262 #define ntAccessSpec 410
00263 #define ntUserAccessSpec 411
00264 #define ntUserdefKeyword 412
00265 #define ntExternTemplate 413
00266 #define ntAccessDecl 414
00267 #define ntNamespaceSpec 415
00268 #define ntUsing 416
00269 #define ntTemplateInstantiation 417
00270
00271 #define ntIfStatement 420
00272 #define ntSwitchStatement 421
00273 #define ntWhileStatement 422
00274 #define ntDoStatement 423
00275 #define ntForStatement 424
00276 #define ntBreakStatement 425
00277 #define ntContinueStatement 426
00278 #define ntReturnStatement 427
00279 #define ntGotoStatement 428
00280 #define ntCaseStatement 429
00281 #define ntDefaultStatement 430
00282 #define ntLabelStatement 431
00283 #define ntExprStatement 432
00284 #define ntTryStatement 433
00285
00286 #define ntCommaExpr 450
00287 #define ntAssignExpr 451
00288 #define ntCondExpr 452
00289 #define ntInfixExpr 453
00290 #define ntPmExpr 454
00291 #define ntCastExpr 455
00292 #define ntUnaryExpr 456
00293 #define ntSizeofExpr 457
00294 #define ntNewExpr 458
00295 #define ntDeleteExpr 459
00296 #define ntArrayExpr 460
00297 #define ntFuncallExpr 461
00298 #define ntPostfixExpr 462
00299 #define ntUserStatementExpr 463
00300 #define ntDotMemberExpr 464
00301 #define ntArrowMemberExpr 465
00302 #define ntParenExpr 466
00303 #define ntStaticUserStatementExpr 467
00304 #define ntThrowExpr 468
00305
00306 #define Ignore 500
00307 #define ASM 501
00308 #define DECLSPEC 502
00309 #define INT64 503
00310
00311 #endif