]> git.sur5r.net Git - cc65/blob - src/cc65/scanner.h
Fixed an error handling SC_EXTERN.
[cc65] / src / cc65 / scanner.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 scanner.h                                 */
4 /*                                                                           */
5 /*                      Source file line info structure                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2004 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 52                                             */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef SCANNER_H
37 #define SCANNER_H
38
39
40
41 /* cc65 */
42 #include "datatype.h"
43 #include "ident.h"
44 #include "lineinfo.h"
45
46
47
48 /*****************************************************************************/
49 /*                             Token definitions                             */
50 /*****************************************************************************/
51
52
53
54 typedef enum token_t {
55     TOK_INVALID,
56     TOK_CEOF,
57
58     /* Storage specifiers */
59     TOK_FIRST_STORAGE_CLASS,
60     TOK_AUTO            = TOK_FIRST_STORAGE_CLASS,
61     TOK_EXTERN,
62     TOK_REGISTER,
63     TOK_STATIC,
64     TOK_TYPEDEF,
65     TOK_LAST_STORAGE_CLASS = TOK_TYPEDEF,
66
67     /* Tokens denoting type qualifiers */
68     TOK_FIRST_TYPEQUAL,
69     TOK_CONST           = TOK_FIRST_TYPEQUAL,
70     TOK_VOLATILE,
71     TOK_RESTRICT,
72     TOK_LAST_TYPEQUAL   = TOK_RESTRICT,
73
74     /* Function specifiers */
75     TOK_INLINE,
76     TOK_FASTCALL,
77
78     /* Tokens denoting types */
79     TOK_FIRST_TYPE,
80     TOK_ENUM            = TOK_FIRST_TYPE,
81     TOK_CHAR,
82     TOK_INT,
83     TOK_DOUBLE,
84     TOK_FLOAT,
85     TOK_LONG,
86     TOK_UNSIGNED,
87     TOK_SIGNED,
88     TOK_SHORT,
89     TOK_STRUCT,
90     TOK_UNION,
91     TOK_VOID,
92     TOK_LAST_TYPE       = TOK_VOID,
93
94     /* Control statements */
95     TOK_DO,
96     TOK_FOR,
97     TOK_GOTO,
98     TOK_IF,
99     TOK_RETURN,
100     TOK_SWITCH,
101     TOK_WHILE,
102
103     TOK_ASM,
104     TOK_CASE,
105     TOK_DEFAULT,
106     TOK_BREAK,
107     TOK_CONTINUE,
108     TOK_ELSE,
109     TOK_ELLIPSIS,
110     TOK_SIZEOF,
111
112     TOK_IDENT,
113     TOK_SEMI,
114
115     /* Primary operators */
116     TOK_LBRACK,
117     TOK_LPAREN,
118     TOK_DOT,
119     TOK_PTR_REF,
120
121     TOK_LCURLY,
122     TOK_RBRACK,
123     TOK_COMP,
124     TOK_INC,
125     TOK_PLUS_ASSIGN,
126     TOK_PLUS,
127     TOK_COMMA,
128     TOK_DEC,
129     TOK_MINUS_ASSIGN,
130     TOK_RCURLY,
131     TOK_MINUS,
132     TOK_MUL_ASSIGN,
133     TOK_STAR,
134     TOK_MUL = TOK_STAR,         /* Alias */
135     TOK_DIV_ASSIGN,
136     TOK_DIV,
137     TOK_BOOL_AND,
138     TOK_AND_ASSIGN,
139     TOK_AND,
140     TOK_NE,
141     TOK_BOOL_NOT,
142     TOK_BOOL_OR,
143     TOK_OR_ASSIGN,
144     TOK_OR,
145     TOK_EQ,
146     TOK_ASSIGN,
147
148     /* Inequalities */
149     TOK_LE,
150     TOK_LT,
151     TOK_GE,
152     TOK_GT,
153
154     TOK_SHL_ASSIGN,
155     TOK_SHL,
156     TOK_SHR_ASSIGN,
157     TOK_SHR,
158     TOK_XOR_ASSIGN,
159     TOK_XOR,
160     TOK_MOD_ASSIGN,
161     TOK_MOD,
162     TOK_QUEST,
163     TOK_COLON,
164     TOK_RPAREN,
165     TOK_SCONST,
166     TOK_ICONST,
167     TOK_CCONST,
168     TOK_FCONST,
169
170     TOK_ATTRIBUTE,
171     TOK_FAR,
172     TOK_NEAR,
173     TOK_A,
174     TOK_X,
175     TOK_Y,
176     TOK_AX,
177     TOK_EAX,
178
179     TOK_PRAGMA
180 } token_t;
181
182
183
184 /*****************************************************************************/
185 /*                                   data                                    */
186 /*****************************************************************************/
187
188
189
190 /* Token stuff */
191 typedef struct Token Token;
192 struct Token {
193     token_t     Tok;            /* The token itself */
194     long        IVal;           /* The integer attribute */
195     double      FVal;           /* The float attribute */
196     ident       Ident;          /* Identifier if IDENT */
197     LineInfo*   LI;             /* Source line where the token comes from */
198     Type*       Type;           /* Type if integer or float constant */
199 };
200
201 extern Token CurTok;            /* The current token */
202 extern Token NextTok;           /* The next token */
203
204
205
206 /*****************************************************************************/
207 /*                                   code                                    */
208 /*****************************************************************************/
209
210
211
212 #if defined(HAVE_INLINE)
213 INLINE int TokIsStorageClass (const Token* T)
214 /* Return true if the token is a storage class specifier */
215 {
216     return (T->Tok >= TOK_FIRST_STORAGE_CLASS && T->Tok <= TOK_LAST_STORAGE_CLASS);
217 }
218 #else
219 #  define TokIsStorageClass(T)  \
220         ((T)->Tok >= TOK_FIRST_STORAGE_CLASS && (T)->Tok <= TOK_LAST_STORAGE_CLASS)
221 #endif
222
223 #if defined(HAVE_INLINE)
224 INLINE int TokIsType (const Token* T)
225 /* Return true if the token is a type */
226 {
227     return (T->Tok >= TOK_FIRST_TYPE && T->Tok <= TOK_LAST_TYPE);
228 }
229 #else
230 #  define TokIsType(T)  ((T)->Tok >= TOK_FIRST_TYPE && (T)->Tok <= TOK_LAST_TYPE)
231 #endif
232
233 #if defined(HAVE_INLINE)
234 INLINE int TokIsTypeQual (const Token* T)
235 /* Return true if the token is a type qualifier */
236 {
237     return (T->Tok >= TOK_FIRST_TYPEQUAL && T->Tok <= TOK_LAST_TYPEQUAL);
238 }
239 #else
240 #  define TokIsTypeQual(T)  ((T)->Tok >= TOK_FIRST_TYPEQUAL && (T)->Tok <= TOK_LAST_TYPEQUAL)
241 #endif
242
243 int TokIsFuncSpec (const Token* T);
244 /* Return true if the token is a function specifier */
245
246 void SymName (char* S);
247 /* Read a symbol from the input stream. The first character must have been
248  * checked before calling this function. The buffer is expected to be at
249  * least of size MAX_IDENTLEN+1.
250  */
251
252 int IsSym (char* S);
253 /* If a symbol follows, read it and return 1, otherwise return 0 */
254
255 void NextToken (void);
256 /* Get next token from input stream */
257
258 void SkipTokens (const token_t* TokenList, unsigned TokenCount);
259 /* Skip tokens until we reach TOK_CEOF or a token in the given token list.
260  * This routine is used for error recovery.
261  */
262
263 int Consume (token_t Token, const char* ErrorMsg);
264 /* Eat token if it is the next in the input stream, otherwise print an error
265  * message. Returns true if the token was found and false otherwise.
266  */
267
268 int ConsumeColon (void);
269 /* Check for a colon and skip it. */
270
271 int ConsumeSemi (void);
272 /* Check for a semicolon and skip it. */
273
274 int ConsumeComma (void);
275 /* Check for a comma and skip it. */
276
277 int ConsumeLParen (void);
278 /* Check for a left parenthesis and skip it */
279
280 int ConsumeRParen (void);
281 /* Check for a right parenthesis and skip it */
282
283 int ConsumeLBrack (void);
284 /* Check for a left bracket and skip it */
285
286 int ConsumeRBrack (void);
287 /* Check for a right bracket and skip it */
288
289 int ConsumeLCurly (void);
290 /* Check for a left curly brace and skip it */
291
292 int ConsumeRCurly (void);
293 /* Check for a right curly brace and skip it */
294
295
296
297 /* End of scanner.h */
298 #endif
299
300
301
302
303
304