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