]> git.sur5r.net Git - cc65/blob - src/ca65/scanner.h
d347e7a200bf658254c037c564c913c9edee11b4
[cc65] / src / ca65 / scanner.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 scanner.h                                 */
4 /*                                                                           */
5 /*                  The scanner for the ca65 macroassembler                  */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2005 Ullrich von Bassewitz                                       */
10 /*               Römerstraße 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 /* common */
42 #include "filepos.h"
43 #include "inline.h"
44
45
46
47 /*****************************************************************************/
48 /*                                   Data                                    */
49 /*****************************************************************************/
50
51
52
53 /* Tokens */
54 enum Token {
55     TOK_NONE,           /* Start value, invalid */
56     TOK_EOF,            /* End of input file */
57     TOK_SEP,            /* Separator (usually newline) */
58     TOK_IDENT,          /* An identifier */
59     TOK_LOCAL_IDENT,    /* A cheap local identifier */
60
61     TOK_INTCON,         /* Integer constant */
62     TOK_CHARCON,        /* Character constant */
63     TOK_STRCON,         /* String constant */
64
65     TOK_A,              /* A)ccumulator */
66     TOK_X,              /* X register */
67     TOK_Y,              /* Y register */
68     TOK_S,              /* S register */
69     TOK_REG,            /* Sweet16 R.. register (in sweet16 mode) */
70
71     TOK_ASSIGN,         /* := */
72     TOK_ULABEL,         /* :++ or :-- */
73
74     TOK_EQ,             /* = */
75     TOK_NE,             /* <> */
76     TOK_LT,             /* < */
77     TOK_GT,             /* > */
78     TOK_LE,             /* <= */
79     TOK_GE,             /* >= */
80
81     TOK_BOOLAND,        /* .and */
82     TOK_BOOLOR,         /* .or */
83     TOK_BOOLXOR,        /* .xor */
84     TOK_BOOLNOT,        /* .not */
85
86     TOK_PLUS,           /* + */
87     TOK_MINUS,          /* - */
88     TOK_MUL,            /* * */
89     TOK_STAR = TOK_MUL, /* Alias */
90     TOK_DIV,            /* / */
91     TOK_MOD,            /* ! */
92     TOK_OR,             /* | */
93     TOK_XOR,            /* ^ */
94     TOK_BANK = TOK_XOR, /* Alias */
95     TOK_AND,            /* & */
96     TOK_SHL,            /* << */
97     TOK_SHR,            /* >> */
98     TOK_NOT,            /* ~ */
99
100     TOK_PC,             /* $ if enabled */
101     TOK_NAMESPACE,      /* :: */
102     TOK_DOT,            /* . */
103     TOK_COMMA,          /* , */
104     TOK_HASH,           /* # */
105     TOK_COLON,          /* : */
106     TOK_LPAREN,         /* ( */
107     TOK_RPAREN,         /* ) */
108     TOK_LBRACK,         /* [ */
109     TOK_RBRACK,         /* ] */
110     TOK_LCURLY,         /* { */
111     TOK_RCURLY,         /* } */
112     TOK_AT,             /* @ - in Sweet16 mode */
113
114     TOK_OVERRIDE_ZP,    /* z: */
115     TOK_OVERRIDE_ABS,   /* a: */
116     TOK_OVERRIDE_FAR,   /* f: */
117
118     TOK_MACPARAM,       /* Macro parameter, not generated by scanner */
119     TOK_REPCOUNTER,     /* Repeat counter, not generated by scanner */
120
121     /* The next ones are tokens for the pseudo instructions. Keep together! */
122     TOK_FIRSTPSEUDO,
123     TOK_A16             = TOK_FIRSTPSEUDO,
124     TOK_A8,
125     TOK_ADDR,
126     TOK_ALIGN,
127     TOK_ASCIIZ,
128     TOK_ASSERT,
129     TOK_AUTOIMPORT,
130     TOK_BANKBYTE,
131     TOK_BLANK,
132     TOK_BSS,
133     TOK_BYTE,
134     TOK_CASE,
135     TOK_CHARMAP,
136     TOK_CODE,
137     TOK_CONCAT,
138     TOK_CONDES,
139     TOK_CONST,
140     TOK_CONSTRUCTOR,
141     TOK_CPU,
142     TOK_DATA,
143     TOK_DBG,
144     TOK_DBYT,
145     TOK_DEBUGINFO,
146     TOK_DEFINE,
147     TOK_DEFINED,
148     TOK_DESTRUCTOR,
149     TOK_DWORD,
150     TOK_ELSE,
151     TOK_ELSEIF,
152     TOK_END,
153     TOK_ENDENUM,
154     TOK_ENDIF,
155     TOK_ENDMACRO,
156     TOK_ENDPROC,
157     TOK_ENDREP,
158     TOK_ENDSCOPE,
159     TOK_ENDSTRUCT,
160     TOK_ENDUNION,
161     TOK_ENUM,
162     TOK_ERROR,
163     TOK_EXITMACRO,
164     TOK_EXPORT,
165     TOK_EXPORTZP,
166     TOK_FARADDR,
167     TOK_FEATURE,
168     TOK_FILEOPT,
169     TOK_FORCEIMPORT,
170     TOK_FORCEWORD,
171     TOK_GLOBAL,
172     TOK_GLOBALZP,
173     TOK_HIBYTE,
174     TOK_HIWORD,
175     TOK_I16,
176     TOK_I8,
177     TOK_MAKEIDENT,
178     TOK_IF,
179     TOK_IFBLANK,
180     TOK_IFCONST,
181     TOK_IFDEF,
182     TOK_IFNBLANK,
183     TOK_IFNCONST,
184     TOK_IFNDEF,
185     TOK_IFNREF,
186     TOK_IFP02,
187     TOK_IFP816,
188     TOK_IFPC02,
189     TOK_IFPSC02,
190     TOK_IFREF,
191     TOK_IMPORT,
192     TOK_IMPORTZP,
193     TOK_INCBIN,
194     TOK_INCLUDE,
195     TOK_INTERRUPTOR,
196     TOK_LEFT,
197     TOK_LINECONT,
198     TOK_LIST,
199     TOK_LISTBYTES,
200     TOK_LOBYTE,
201     TOK_LOCAL,
202     TOK_LOCALCHAR,
203     TOK_LOWORD,
204     TOK_MACPACK,
205     TOK_MACRO,
206     TOK_MATCH,
207     TOK_MID,
208     TOK_NULL,
209     TOK_ORG,
210     TOK_OUT,
211     TOK_P02,
212     TOK_P816,
213     TOK_PAGELENGTH,
214     TOK_PARAMCOUNT,
215     TOK_PC02,
216     TOK_POPSEG,
217     TOK_PROC,
218     TOK_PSC02,
219     TOK_PUSHSEG,
220     TOK_REFERENCED,
221     TOK_RELOC,
222     TOK_REPEAT,
223     TOK_RES,
224     TOK_RIGHT,
225     TOK_RODATA,
226     TOK_SCOPE,
227     TOK_SEGMENT,
228     TOK_SET,
229     TOK_SETCPU,
230     TOK_SIZEOF,
231     TOK_SMART,
232     TOK_SPRINTF,
233     TOK_STRAT,
234     TOK_STRING,
235     TOK_STRLEN,
236     TOK_STRUCT,
237     TOK_SUNPLUS,
238     TOK_TAG,
239     TOK_TCOUNT,
240     TOK_TIME,
241     TOK_UNION,
242     TOK_VERSION,
243     TOK_WARNING,
244     TOK_WORD,
245     TOK_XMATCH,
246     TOK_ZEROPAGE,
247     TOK_LASTPSEUDO      = TOK_ZEROPAGE,
248
249     TOK_COUNT           /* Count of tokens */
250 };
251
252
253
254 /* Scanner variables */
255 #define MAX_INPUT_FILES 254             /* No more than this files total */
256 #define MAX_STR_LEN     255             /* Maximum length of any string */
257 extern enum Token Tok;                  /* Current token */
258 extern int WS;                          /* Flag: Whitespace before token */
259 extern long IVal;                       /* Integer token attribute */
260 extern char SVal [MAX_STR_LEN+1];       /* String token attribute */
261
262 extern FilePos  CurPos;                 /* Name and position in file */
263 extern int      ForcedEnd;              /* Force end of assembly */
264
265
266
267 /*****************************************************************************/
268 /*                                   Code                                    */
269 /*****************************************************************************/
270
271
272
273 int IsIdChar (int C);
274 /* Return true if the character is a valid character for an identifier */
275
276 int IsIdStart (int C);
277 /* Return true if the character may start an identifier */
278
279 void NewInputFile (const char* Name);
280 /* Open a new input file */
281
282 void DoneInputFile (void);
283 /* Close the current input file */
284
285 void NewInputData (char* Data, int Malloced);
286 /* Add a chunk of input data to the input stream */
287
288 void LocaseSVal (void);
289 /* Make SVal lower case */
290
291 void UpcaseSVal (void);
292 /* Make SVal upper case */
293
294 void NextRawTok (void);
295 /* Read the next raw token from the input stream */
296
297 int TokHasSVal (enum Token Tok);
298 /* Return true if the given token has an attached SVal */
299
300 int TokHasIVal (enum Token Tok);
301 /* Return true if the given token has an attached IVal */
302
303 #if defined(HAVE_INLINE)
304 INLINE int TokIsSep (enum Token T)
305 /* Return true if this is a separator token */
306 {
307     return (T == TOK_SEP || T == TOK_EOF);
308 }
309 #else
310 #  define TokIsSep(T)   (T == TOK_SEP || T == TOK_EOF)
311 #endif
312
313 int GetSubKey (const char** Keys, unsigned Count);
314 /* Search for a subkey in a table of keywords. The current token must be an
315  * identifier and all keys must be in upper case. The identifier will be
316  * uppercased in the process. The function returns the index of the keyword,
317  * or -1 if the keyword was not found.
318  */
319
320 unsigned char ParseAddrSize (void);
321 /* Check if the next token is a keyword that denotes an address size specifier.
322  * If so, return the corresponding address size constant, otherwise output an
323  * error message and return ADDR_SIZE_DEFAULT.
324  */
325
326 void InitScanner (const char* InFile);
327 /* Initialize the scanner, open the given input file */
328
329 void DoneScanner (void);
330 /* Release scanner resources */
331
332
333
334 /* End of scanner.h */
335
336 #endif
337
338
339