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