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