]> git.sur5r.net Git - cc65/blob - src/ca65/scanner.h
Allow token lists to be optionally enclosed in curly braces. Using such
[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_LEFT,
193     TOK_LINECONT,
194     TOK_LIST,
195     TOK_LISTBYTES,
196     TOK_LOBYTE,
197     TOK_LOCAL,
198     TOK_LOCALCHAR,
199     TOK_LOWORD,
200     TOK_MACPACK,
201     TOK_MACRO,
202     TOK_MATCH,
203     TOK_MID,
204     TOK_NULL,
205     TOK_ORG,
206     TOK_OUT,
207     TOK_P02,
208     TOK_P816,
209     TOK_PAGELENGTH,
210     TOK_PARAMCOUNT,
211     TOK_PC02,
212     TOK_POPSEG,
213     TOK_PROC,
214     TOK_PSC02,
215     TOK_PUSHSEG,
216     TOK_REFERENCED,
217     TOK_RELOC,
218     TOK_REPEAT,
219     TOK_RES,
220     TOK_RIGHT,
221     TOK_RODATA,
222     TOK_SCOPE,
223     TOK_SEGMENT,
224     TOK_SETCPU,
225     TOK_SIZEOF,
226     TOK_SMART,
227     TOK_STRAT,
228     TOK_STRING,
229     TOK_STRLEN,
230     TOK_STRUCT,
231     TOK_SUNPLUS,
232     TOK_TAG,
233     TOK_TCOUNT,
234     TOK_TIME,
235     TOK_UNION,
236     TOK_VERSION,
237     TOK_WARNING,
238     TOK_WORD,
239     TOK_XMATCH,
240     TOK_ZEROPAGE,
241     TOK_LASTPSEUDO      = TOK_ZEROPAGE,
242
243     TOK_COUNT           /* Count of tokens */
244 };
245
246
247
248 /* Scanner variables */
249 #define MAX_INPUT_FILES 254             /* No more than this files total */
250 #define MAX_STR_LEN     255             /* Maximum length of any string */
251 extern enum Token Tok;                  /* Current token */
252 extern int WS;                          /* Flag: Whitespace before token */
253 extern long IVal;                       /* Integer token attribute */
254 extern char SVal [MAX_STR_LEN+1];       /* String token attribute */
255
256 extern FilePos  CurPos;                 /* Name and position in file */
257 extern int      ForcedEnd;              /* Force end of assembly */
258
259
260
261 /*****************************************************************************/
262 /*                                   Code                                    */
263 /*****************************************************************************/
264
265
266
267 void NewInputFile (const char* Name);
268 /* Open a new input file */
269
270 void DoneInputFile (void);
271 /* Close the current input file */
272
273 void NewInputData (char* Data, int Malloced);
274 /* Add a chunk of input data to the input stream */
275
276 void LocaseSVal (void);
277 /* Make SVal lower case */
278
279 void UpcaseSVal (void);
280 /* Make SVal upper case */
281
282 void NextRawTok (void);
283 /* Read the next raw token from the input stream */
284
285 int TokHasSVal (enum Token Tok);
286 /* Return true if the given token has an attached SVal */
287
288 int TokHasIVal (enum Token Tok);
289 /* Return true if the given token has an attached IVal */
290
291 #if defined(HAVE_INLINE)
292 INLINE int TokIsSep (enum Token T)
293 /* Return true if this is a separator token */
294 {
295     return (T == TOK_SEP || T == TOK_EOF);
296 }
297 #else
298 #  define TokIsSep(T)   (T == TOK_SEP || T == TOK_EOF)
299 #endif
300
301 int GetSubKey (const char** Keys, unsigned Count);
302 /* Search for a subkey in a table of keywords. The current token must be an
303  * identifier and all keys must be in upper case. The identifier will be
304  * uppercased in the process. The function returns the index of the keyword,
305  * or -1 if the keyword was not found.
306  */
307
308 unsigned char ParseAddrSize (void);
309 /* Check if the next token is a keyword that denotes an address size specifier.
310  * If so, return the corresponding address size constant, otherwise output an
311  * error message and return ADDR_SIZE_DEFAULT.
312  */
313
314 void InitScanner (const char* InFile);
315 /* Initialize the scanner, open the given input file */
316
317 void DoneScanner (void);
318 /* Release scanner resources */
319
320
321
322 /* End of scanner.h */
323
324 #endif
325
326
327