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