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