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