]> git.sur5r.net Git - cc65/blob - src/cc65/scanner.h
Introduce a -E flag that activates just the preprocessor.
[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     TOK_AUTO,
59     TOK_EXTERN,
60     TOK_REGISTER,
61     TOK_RESTRICT,
62     TOK_STATIC,
63     TOK_TYPEDEF,
64
65     /* Tokens denoting type qualifiers */
66     TOK_FIRST_TYPEQUAL,
67     TOK_CONST           = TOK_FIRST_TYPEQUAL,
68     TOK_VOLATILE,
69     TOK_LAST_TYPEQUAL   = TOK_VOLATILE,
70
71     /* Tokens denoting types */
72     TOK_FIRST_TYPE,
73     TOK_ENUM            = TOK_FIRST_TYPE,
74     TOK_CHAR,
75     TOK_INT,
76     TOK_DOUBLE,
77     TOK_FLOAT,
78     TOK_LONG,
79     TOK_UNSIGNED,
80     TOK_SIGNED,
81     TOK_SHORT,
82     TOK_STRUCT,
83     TOK_UNION,
84     TOK_VOID,
85     TOK_LAST_TYPE       = TOK_VOID,
86
87     /* Control statements */
88     TOK_DO,
89     TOK_FOR,
90     TOK_GOTO,
91     TOK_IF,
92     TOK_RETURN,
93     TOK_SWITCH,
94     TOK_WHILE,
95
96     TOK_ASM,
97     TOK_CASE,
98     TOK_DEFAULT,
99     TOK_BREAK,
100     TOK_CONTINUE,
101     TOK_ELSE,
102     TOK_ELLIPSIS,
103     TOK_SIZEOF,
104
105     TOK_IDENT,
106     TOK_SEMI,
107
108     /* Primary operators */
109     TOK_LBRACK,
110     TOK_LPAREN,
111     TOK_DOT,
112     TOK_PTR_REF,
113
114     TOK_LCURLY,
115     TOK_RBRACK,
116     TOK_COMP,
117     TOK_INC,
118     TOK_PLUS_ASSIGN,
119     TOK_PLUS,
120     TOK_COMMA,
121     TOK_DEC,
122     TOK_MINUS_ASSIGN,
123     TOK_RCURLY,
124     TOK_MINUS,
125     TOK_MUL_ASSIGN,
126     TOK_STAR,
127     TOK_MUL = TOK_STAR,         /* Alias */
128     TOK_DIV_ASSIGN,
129     TOK_DIV,
130     TOK_BOOL_AND,
131     TOK_AND_ASSIGN,
132     TOK_AND,
133     TOK_NE,
134     TOK_BOOL_NOT,
135     TOK_BOOL_OR,
136     TOK_OR_ASSIGN,
137     TOK_OR,
138     TOK_EQ,
139     TOK_ASSIGN,
140
141     /* Inequalities */
142     TOK_LE,
143     TOK_LT,
144     TOK_GE,
145     TOK_GT,
146
147     TOK_SHL_ASSIGN,
148     TOK_SHL,
149     TOK_SHR_ASSIGN,
150     TOK_SHR,
151     TOK_XOR_ASSIGN,
152     TOK_XOR,
153     TOK_MOD_ASSIGN,
154     TOK_MOD,
155     TOK_QUEST,
156     TOK_COLON,
157     TOK_RPAREN,
158     TOK_SCONST,
159     TOK_ICONST,
160     TOK_CCONST,
161     TOK_FCONST,
162
163     TOK_ATTRIBUTE,
164     TOK_FAR,
165     TOK_NEAR,
166     TOK_FASTCALL,
167     TOK_A,
168     TOK_X,
169     TOK_Y,
170     TOK_AX,
171     TOK_EAX,
172
173     TOK_PRAGMA
174 } token_t;
175
176
177
178 /*****************************************************************************/
179 /*                                   data                                    */
180 /*****************************************************************************/
181
182
183
184 /* Token stuff */
185 typedef struct Token Token;
186 struct Token {
187     token_t     Tok;            /* The token itself */
188     long        IVal;           /* The integer attribute */
189     double      FVal;           /* The float attribute */
190     ident       Ident;          /* Identifier if IDENT */
191     LineInfo*   LI;             /* Source line where the token comes from */
192     type*       Type;           /* Type if integer or float constant */
193 };
194
195 extern Token CurTok;            /* The current token */
196 extern Token NextTok;           /* The next token */
197
198
199
200 /*****************************************************************************/
201 /*                                   code                                    */
202 /*****************************************************************************/
203
204
205
206 #if defined(HAVE_INLINE)
207 INLINE int TokIsType (const Token* T)
208 /* Return true if the token is a type */
209 {
210     return (T->Tok >= TOK_FIRST_TYPE && T->Tok <= TOK_LAST_TYPE);
211 }
212 #else
213 #  define TokIsType(T)  ((T)->Tok >= TOK_FIRST_TYPE && (T)->Tok <= TOK_LAST_TYPE)
214 #endif
215
216 #if defined(HAVE_INLINE)
217 INLINE int TokIsTypeQual (const Token* T)
218 /* Return true if the token is a type qualifier */
219 {
220     return (T->Tok >= TOK_FIRST_TYPEQUAL && T->Tok <= TOK_LAST_TYPEQUAL);
221 }
222 #else
223 #  define TokIsTypeQual(T)  ((T)->Tok >= TOK_FIRST_TYPEQUAL && (T)->Tok <= TOK_LAST_TYPEQUAL)
224 #endif
225
226 void SymName (char* S);
227 /* Read a symbol from the input stream. The first character must have been
228  * checked before calling this function. The buffer is expected to be at
229  * least of size MAX_IDENTLEN+1.
230  */
231
232 int IsSym (char* S);
233 /* If a symbol follows, read it and return 1, otherwise return 0 */
234
235 void NextToken (void);
236 /* Get next token from input stream */
237
238 void SkipTokens (const token_t* TokenList, unsigned TokenCount);
239 /* Skip tokens until we reach TOK_CEOF or a token in the given token list.
240  * This routine is used for error recovery.
241  */
242
243 int Consume (token_t Token, const char* ErrorMsg);
244 /* Eat token if it is the next in the input stream, otherwise print an error
245  * message. Returns true if the token was found and false otherwise.
246  */
247
248 int ConsumeColon (void);
249 /* Check for a colon and skip it. */
250
251 int ConsumeSemi (void);
252 /* Check for a semicolon and skip it. */
253
254 int ConsumeComma (void);
255 /* Check for a comma and skip it. */
256
257 int ConsumeLParen (void);
258 /* Check for a left parenthesis and skip it */
259
260 int ConsumeRParen (void);
261 /* Check for a right parenthesis and skip it */
262
263 int ConsumeLBrack (void);
264 /* Check for a left bracket and skip it */
265
266 int ConsumeRBrack (void);
267 /* Check for a right bracket and skip it */
268
269 int ConsumeLCurly (void);
270 /* Check for a left curly brace and skip it */
271
272 int ConsumeRCurly (void);
273 /* Check for a right curly brace and skip it */
274
275
276
277 /* End of scanner.h */
278 #endif
279
280
281
282
283
284