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