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