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