Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

token.h

Go to the documentation of this file.
00001 /*
00002   Copyright (C) 1997-2001 Shigeru Chiba, Tokyo Institute of Technology.
00003 
00004   Permission to use, copy, distribute and modify this software and   
00005   its documentation for any purpose is hereby granted without fee,        
00006   provided that the above copyright notice appear in all copies and that 
00007   both that copyright notice and this permission notice appear in 
00008   supporting documentation.
00009 
00010   Shigeru Chiba makes no representations about the suitability of this 
00011   software for any purpose.  It is provided "as is" without express or
00012   implied warranty.
00013 */
00014 
00015 /*
00016   Copyright (c) 1995, 1996 Xerox Corporation.
00017   All Rights Reserved.
00018 
00019   Use and copying of this software and preparation of derivative works
00020   based upon this software are permitted. Any copy of this software or
00021   of any derivative work must include the above copyright notice of
00022   Xerox Corporation, this paragraph and the one after it.  Any
00023   distribution of this software or derivative works must comply with all
00024   applicable United States export control laws.
00025 
00026   This software is made available AS IS, and XEROX CORPORATION DISCLAIMS
00027   ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
00028   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029   PURPOSE, AND NOTWITHSTANDING ANY OTHER PROVISION CONTAINED HEREIN, ANY
00030   LIABILITY FOR DAMAGES RESULTING FROM THE SOFTWARE OR ITS USE IS
00031   EXPRESSLY DISCLAIMED, WHETHER ARISING IN CONTRACT, TORT (INCLUDING
00032   NEGLIGENCE) OR STRICT LIABILITY, EVEN IF XEROX CORPORATION IS ADVISED
00033   OF THE POSSIBILITY OF SUCH DAMAGES.
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 // class Token
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 // class Lex
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 // convenient functions
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 // tokens
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     /* must be consistent with Class::Private */
00206 #define PROTECTED       297     /* must be consistent with Class::Protected */
00207 #define PUBLIC          298     /* must be consistent with Class::Public */
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 // non terminals
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 /* _token_h */

Generated on Mon Feb 10 17:32:58 2003 for VFiasco Semantics Compiler by doxygen1.2.15