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