2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 by Digital Mars
5 // written by Walter Bright
6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
29 < > <= >= == != === !==
30 << >> <<= >>= >>> >>>=
46 TOKlbracket
, TOKrbracket
,
49 TOKsemicolon
, TOKdotdotdot
,
54 TOKaddress
, TOKtypedot
,
61 TOKarraylength
, TOKversion
,
63 TOKtemplate
, TOKdottd
,
64 TOKdeclaration
, TOKtypeof
,
65 TOKpragma
, TOKdsymbol
,
68 TOKnewanonclass
, TOKcomment
,
69 TOKarrayliteral
, TOKassocarrayliteral
,
75 TOKequal
, TOKnotequal
,
76 TOKidentity
, TOKnotidentity
,
81 // NCEG floating point compares
82 // !<>= <> <>= !> !>= !< !<= !<>
83 TOKunord
,TOKlg
,TOKleg
,TOKule
,TOKul
,TOKuge
,TOKug
,TOKue
,
88 TOKcat
, TOKcatass
, // ~ ~=
89 TOKadd
, TOKmin
, TOKaddass
, TOKminass
,
90 TOKmul
, TOKdiv
, TOKmod
,
91 TOKmulass
, TOKdivass
, TOKmodass
,
92 TOKand
, TOKor
, TOKxor
,
93 TOKandass
, TOKorass
, TOKxorass
,
94 TOKassign
, TOKnot
, TOKtilde
,
95 TOKplusplus
, TOKminusminus
, TOKconstruct
, TOKblit
,
96 TOKdot
, TOKarrow
, TOKcomma
,
97 TOKquestion
, TOKandand
, TOKoror
,
101 TOKint32v
, TOKuns32v
,
102 TOKint64v
, TOKuns64v
,
103 TOKfloat32v
, TOKfloat64v
, TOKfloat80v
,
104 TOKimaginary32v
, TOKimaginary64v
, TOKimaginary80v
,
107 TOKcharv
, TOKwcharv
, TOKdcharv
,
110 TOKidentifier
, TOKstring
,
120 TOKfloat32
, TOKfloat64
, TOKfloat80
,
121 TOKimaginary32
, TOKimaginary64
, TOKimaginary80
,
122 TOKcomplex32
, TOKcomplex64
, TOKcomplex80
,
123 TOKchar
, TOKwchar
, TOKdchar
, TOKbit
, TOKbool
,
127 TOKstruct
, TOKclass
, TOKinterface
, TOKunion
, TOKenum
, TOKimport
,
128 TOKtypedef
, TOKalias
, TOKoverride
, TOKdelegate
, TOKfunction
,
131 TOKalign
, TOKextern
, TOKprivate
, TOKprotected
, TOKpublic
, TOKexport
,
132 TOKstatic
, /*TOKvirtual,*/ TOKfinal
, TOKconst
, TOKabstract
, TOKvolatile
,
133 TOKdebug
, TOKdeprecated
, TOKin
, TOKout
, TOKinout
, TOKlazy
,
134 TOKauto
, TOKpackage
, TOKmanifest
,
137 TOKif
, TOKelse
, TOKwhile
, TOKfor
, TOKdo
, TOKswitch
,
138 TOKcase
, TOKdefault
, TOKbreak
, TOKcontinue
, TOKwith
,
139 TOKsynchronized
, TOKreturn
, TOKgoto
, TOKtry
, TOKcatch
, TOKfinally
,
140 TOKasm
, TOKforeach
, TOKforeach_reverse
,
142 TOKon_scope_exit
, TOKon_scope_failure
, TOKon_scope_success
,
145 TOKbody
, TOKinvariant
,
166 #define CASE_BASIC_TYPES \
167 case TOKwchar: case TOKdchar: \
168 case TOKbit: case TOKbool: case TOKchar: \
169 case TOKint8: case TOKuns8: \
170 case TOKint16: case TOKuns16: \
171 case TOKint32: case TOKuns32: \
172 case TOKint64: case TOKuns64: \
173 case TOKfloat32: case TOKfloat64: case TOKfloat80: \
174 case TOKimaginary32: case TOKimaginary64: case TOKimaginary80: \
175 case TOKcomplex32: case TOKcomplex64: case TOKcomplex80: \
178 #define CASE_BASIC_TYPES_X(t) \
179 case TOKvoid: t = Type::tvoid; goto LabelX; \
180 case TOKint8: t = Type::tint8; goto LabelX; \
181 case TOKuns8: t = Type::tuns8; goto LabelX; \
182 case TOKint16: t = Type::tint16; goto LabelX; \
183 case TOKuns16: t = Type::tuns16; goto LabelX; \
184 case TOKint32: t = Type::tint32; goto LabelX; \
185 case TOKuns32: t = Type::tuns32; goto LabelX; \
186 case TOKint64: t = Type::tint64; goto LabelX; \
187 case TOKuns64: t = Type::tuns64; goto LabelX; \
188 case TOKfloat32: t = Type::tfloat32; goto LabelX; \
189 case TOKfloat64: t = Type::tfloat64; goto LabelX; \
190 case TOKfloat80: t = Type::tfloat80; goto LabelX; \
191 case TOKimaginary32: t = Type::timaginary32; goto LabelX; \
192 case TOKimaginary64: t = Type::timaginary64; goto LabelX; \
193 case TOKimaginary80: t = Type::timaginary80; goto LabelX; \
194 case TOKcomplex32: t = Type::tcomplex32; goto LabelX; \
195 case TOKcomplex64: t = Type::tcomplex64; goto LabelX; \
196 case TOKcomplex80: t = Type::tcomplex80; goto LabelX; \
197 case TOKbit: t = Type::tbit; goto LabelX; \
198 case TOKbool: t = Type::tbool; goto LabelX; \
199 case TOKchar: t = Type::tchar; goto LabelX; \
200 case TOKwchar: t = Type::twchar; goto LabelX; \
201 case TOKdchar: t = Type::tdchar; goto LabelX; \
207 unsigned char *ptr
; // pointer to first character of this token within buffer
209 unsigned char *blockComment
; // doc comment string prior to this token
210 unsigned char *lineComment
; // doc comment for previous token
221 // real_t float80value; // can't use this in a union!
223 d_float80 float80value
;
227 { unsigned char *ustring
; // UTF8 string
229 unsigned char postfix
; // 'c', 'w', 'd'
235 real_t float80value
; // can't use this in a union!
238 static char *tochars
[TOKMAX
];
239 static void *operator new(size_t sz
);
244 static char *toChars(enum TOK
);
249 static StringTable stringtable
;
250 static OutBuffer stringbuffer
;
251 static Token
*freelist
;
253 Loc loc
; // for error messages
255 unsigned char *base
; // pointer to start of buffer
256 unsigned char *end
; // past end of buffer
257 unsigned char *p
; // current character
260 int doDocComment
; // collect doc comment information
261 int anyToken
; // !=0 means seen at least one token
262 int commentToken
; // !=0 means comments are TOKcomment's
265 unsigned char *base
, unsigned begoffset
, unsigned endoffset
,
266 int doDocComment
, int commentToken
);
268 static void initKeywords();
269 static Identifier
*idPool(const char *s
);
270 static Identifier
*uniqueId(const char *s
);
271 static Identifier
*uniqueId(const char *s
, int num
);
275 Token
*peek(Token
*t
);
276 Token
*peekPastParen(Token
*t
);
277 unsigned escapeSequence();
278 TOK
wysiwygStringConstant(Token
*t
, int tc
);
279 TOK
hexStringConstant(Token
*t
);
281 TOK
delimitedStringConstant(Token
*t
);
282 TOK
tokenStringConstant(Token
*t
);
284 TOK
escapeStringConstant(Token
*t
, int wide
);
285 TOK
charConstant(Token
*t
, int wide
);
286 void stringPostfix(Token
*t
);
287 unsigned wchar(unsigned u
);
288 TOK
number(Token
*t
);
289 TOK
inreal(Token
*t
);
290 void error(const char *format
, ...);
291 void error(Loc loc
, const char *format
, ...);
293 unsigned decodeUTF();
294 void getDocComment(Token
*t
, unsigned lineComment
);
296 static int isValidIdentifier(char *p
);
297 static unsigned char *combineComments(unsigned char *c1
, unsigned char *c2
);
300 #endif /* DMD_LEXER_H */