Modules |
Files |
Inheritance Tree |
Inheritance Graph |
Name Index |
Config
File: Synopsis/Parser/C++/occ/token.h
1| /*
2| Copyright (C) 1997-2000 Shigeru Chiba, University of Tsukuba.
3|
4| Permission to use, copy, distribute and modify this software and
5| its documentation for any purpose is hereby granted without fee,
6| provided that the above copyright notice appear in all copies and that
7| both that copyright notice and this permission notice appear in
8| supporting documentation.
9|
10| Shigeru Chiba makes no representations about the suitability of this
11| software for any purpose. It is provided "as is" without express or
12| implied warranty.
13| */
14| /*
15| Copyright (c) 1995, 1996 Xerox Corporation.
16| All Rights Reserved.
17|
18| Use and copying of this software and preparation of derivative works
19| based upon this software are permitted. Any copy of this software or
20| of any derivative work must include the above copyright notice of
21| Xerox Corporation, this paragraph and the one after it. Any
22| distribution of this software or derivative works must comply with all
23| applicable United States export control laws.
24|
25| This software is made available AS IS, and XEROX CORPORATION DISCLAIMS
26| ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
27| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28| PURPOSE, AND NOTWITHSTANDING ANY OTHER PROVISION CONTAINED HEREIN, ANY
29| LIABILITY FOR DAMAGES RESULTING FROM THE SOFTWARE OR ITS USE IS
30| EXPRESSLY DISCLAIMED, WHETHER ARISING IN CONTRACT, TORT (INCLUDING
31| NEGLIGENCE) OR STRICT LIABILITY, EVEN IF XEROX CORPORATION IS ADVISED
32| OF THE POSSIBILITY OF SUCH DAMAGES.
33| */
34|
35| #ifndef _token_h
36| #define _token_h
37|
38| #include "types.h"
39|
40| class Program;
41| class HashTable;
42| class Ptree;
43|
44|
45|
46| class Token {
47| public:
48| bool Eq(char c) { return(*ptr == c && len == 1); }
49|
50| public:
51| char* ptr;
52| int len;
53| int kind;
54| };
55|
56|
57|
58| class Lex : public Object {
59| public:
60| Lex(Program*);
61| int GetToken(Token&);
62| int LookAhead(int);
63| int LookAhead(int, Token&);
64|
65| char* Save();
66| void Restore(char*);
67| void GetOnlyClosingBracket(Token&);
68|
69| Ptree* GetComments();
70| Ptree* GetComments2();
71|
72| uint LineNumber(char*, char*&, int&);
73|
74| static bool RecordKeyword(char*, int);
75| static bool Reify(Ptree*, unsigned int&);
76| static bool Reify(Ptree* t, char*&);
77|
78| private:
79| class TokenFifo {
80| public:
81| TokenFifo(Lex*);
82| ~TokenFifo();
83| void Clear();
84| void Push(int, char*, int);
85| int Pop(char*&, int&);
86| int Peek(int);
87| int Peek(int, char*&, int&);
88| private:
89| int Peek2(int);
90| Lex* lex;
91| int head;
92| int tail;
93| int size;
94| struct Slot {
95| int token;
96| char* pos;
97| int len;
98| }* ring;
99| };
100|
101| friend class TokenFifo;
102|
103| uint Tokenp() { return tokenp; }
104| int TokenLen() { return token_len; }
105| char* TokenPosition();
106| char Ref(uint i);
107| void Rewind(char*);
108|
109| int ReadToken(char*&, int&);
110| void SkipAttributeToken();
111| int SkipExtensionToken(char*&, int&);
112|
113| #if defined(_MSC_VER) || defined(_PARSE_VCC)
114| void SkipAsmToken();
115| void SkipDeclspecToken();
116| #endif
117|
118| char GetNextNonWhiteChar();
119| int ReadLine();
120| bool ReadCharConst(uint top);
121| bool ReadStrConst(uint top);
122| int ReadNumber(char c, uint top);
123| int ReadFloat(uint top);
124| bool ReadLineDirective();
125| int ReadIdentifier(uint top);
126| int Screening(char *identifier, int len);
127| int ReadSeparator(char c, uint top);
128| int SingleCharOp(unsigned char c);
129| int ReadComment(char c, uint top);
130|
131| private:
132| Program* file;
133| TokenFifo fifo;
134| uint tokenp;
135| int token_len;
136| int last_token;
137|
138| static HashTable* user_keywords;
139| static Ptree* comments;
140| };
141|
142|
143|
144| inline bool is_blank(char c){
145| return(c == ' ' || c == '\t' || c == '\f' || c == '\r');
146| }
147|
148| inline bool is_letter(char c){
149| return('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '_'
150| || c == '$');
151| }
152|
153| inline bool is_digit(char c){ return('0' <= c && c <= '9'); }
154|
155| inline bool is_xletter(char c){ return(c == 'X' || c == 'x'); }
156|
157| inline bool is_eletter(char c){ return(c == 'E' || c == 'e'); }
158|
159| inline bool is_hexdigit(char c){
160| return(is_digit(c) || 'A' <= c && c <= 'F' || 'a' <= c && c <= 'f');
161| }
162|
163| inline bool is_int_suffix(char c){
164| return(c == 'U' || c == 'u' || c == 'L' || c == 'l');
165| }
166|
167| inline bool is_float_suffix(char c){
168| return(c == 'F' || c == 'f' || c == 'L' || c == 'l');
169| }
170|
171|
172|
173| #define Identifier
174| #define Constant
175| #define CharConst
176| #define StringL
177| #define AssignOp
178| #define EqualOp
179| #define RelOp
180| #define ShiftOp
181| #define LogOrOp
182| #define LogAndOp
183| #define IncOp
184| #define Scope
185| #define Ellipsis
186| #define PmOp
187| #define ArrowOp
188| #define BadToken
189| #define AUTO
190| #define CHAR
191| #define CLASS
192| #define CONST
193| #define DELETE
194| #define DOUBLE
195| #define ENUM
196| #define EXTERN
197| #define FLOAT
198| #define FRIEND
199| #define INLINE
200| #define INT
201| #define LONG
202| #define NEW
203| #define OPERATOR
204| #define PRIVATE 296 /* must be consistent wi
205| #define PROTECTED 297 /* must be consistent with Class::P
206| #define PUBLIC 298 /* must be consistent with Cla
207| #define REGISTER
208| #define SHORT
209| #define SIGNED
210| #define STATIC
211| #define STRUCT
212| #define TYPEDEF
213| #define UNION
214| #define UNSIGNED
215| #define VIRTUAL
216| #define VOID
217| #define VOLATILE
218| #define TEMPLATE
219| #define MUTABLE
220| #define BREAK
221| #define CASE
222| #define CONTINUE
223| #define DEFAULT
224| #define DO
225| #define ELSE
226| #define FOR
227| #define GOTO
228| #define IF
229| #define RETURN
230| #define SIZEOF
231| #define SWITCH
232| #define THIS
233| #define WHILE
234| #define ATTRIBUTE 326
235| #define METACLASS
236| #define UserKeyword
237| #define UserKeyword2
238| #define UserKeyword3
239| #define UserKeyword4
240| #define BOOLEAN
241| #define EXTENSION 333
242| #define TRY
243| #define CATCH
244| #define THROW
245| #define UserKeyword5
246| #define NAMESPACE
247| #define USING
248| #define TYPEID
249| #define TYPEOF
250|
251|
252|
253| #define ntDeclarator
254| #define ntName
255| #define ntFstyleCast
256| #define ntClassSpec
257| #define ntEnumSpec
258| #define ntDeclaration
259| #define ntTypedef
260| #define ntTemplateDecl 4
261| #define ntMetaclassDecl 40
262| #define ntLinkageSpec
263| #define ntAccessSpec
264| #define ntUserAccessSpec 411
265| #define ntUserdefKeyword 412
266| #define ntExternTemplate 413
267| #define ntAccessDecl
268| #define ntNamespaceSpec 41
269| #define ntUsing
270| #define ntTemplateInstantiation 41
271|
272| #define ntIfStatement
273| #define ntSwitchStatement
274| #define ntWhileStatement
275| #define ntDoStatement
276| #define ntForStatement
277| #define ntBreakStatement
278| #define ntContinueStatement
279| #define ntReturnStatement
280| #define ntGotoStatement
281| #define ntCaseStatement
282| #define ntDefaultStatement
283| #define ntLabelStatement
284| #define ntExprStatement
285| #define ntTryStatement
286|
287| #define ntCommaExpr
288| #define ntAssignExpr
289| #define ntCondExpr
290| #define ntInfixExpr
291| #define ntPmExpr
292| #define ntCastExpr
293| #define ntUnaryExpr
294| #define ntSizeofExpr
295| #define ntNewExpr
296| #define ntDeleteExpr
297| #define ntArrayExpr
298| #define ntFuncallExpr
299| #define ntPostfixExpr
300| #define ntUserStatementExpr
301| #define ntDotMemberExpr
302| #define ntArrowMemberExpr
303| #define ntParenExpr
304| #define ntStaticUserStatementExpr 467
305| #define ntThrowExpr
306| #define ntTypeidExpr
307| #define ntTypeofExpr
308|
309| #define Ignore
310| #define ASM
311| #define DECLSPEC 502
312| #define INT64
313|
314| #endif /* _token_h */