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