]> git.sur5r.net Git - cc65/blob - src/ca65/scanner.h
Use MakeHexArg, replace STX and STY by STZ if possible
[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
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_CHARMAP,
123     TOK_CODE,
124     TOK_CONCAT,
125     TOK_CONDES,
126     TOK_CONST,
127     TOK_CONSTRUCTOR,
128     TOK_CPU,
129     TOK_DATA,
130     TOK_DBG,
131     TOK_DBYT,
132     TOK_DEBUGINFO,
133     TOK_DEFINE,
134     TOK_DEFINED,
135     TOK_DESTRUCTOR,
136     TOK_DWORD,
137     TOK_ELSE,
138     TOK_ELSEIF,
139     TOK_END,
140     TOK_ENDIF,
141     TOK_ENDMACRO,
142     TOK_ENDPROC,
143     TOK_ENDREP,
144     TOK_ERROR,
145     TOK_EXITMACRO,
146     TOK_EXPORT,
147     TOK_EXPORTZP,
148     TOK_FARADDR,
149     TOK_FEATURE,
150     TOK_FILEOPT,
151     TOK_FORCEWORD,
152     TOK_GLOBAL,
153     TOK_GLOBALZP,
154     TOK_I16,
155     TOK_I8,
156     TOK_IF,
157     TOK_IFBLANK,
158     TOK_IFCONST,
159     TOK_IFDEF,
160     TOK_IFNBLANK,
161     TOK_IFNCONST,
162     TOK_IFNDEF,
163     TOK_IFNREF,
164     TOK_IFP02,
165     TOK_IFP816,
166     TOK_IFPC02,
167     TOK_IFREF,
168     TOK_IMPORT,
169     TOK_IMPORTZP,
170     TOK_INCBIN,
171     TOK_INCLUDE,
172     TOK_LEFT,
173     TOK_LINECONT,
174     TOK_LIST,
175     TOK_LISTBYTES,
176     TOK_LOCAL,
177     TOK_LOCALCHAR,
178     TOK_MACPACK,
179     TOK_MACRO,
180     TOK_MATCH,
181     TOK_MID,
182     TOK_NULL,
183     TOK_ORG,
184     TOK_OUT,
185     TOK_P02,
186     TOK_P816,
187     TOK_PAGELENGTH,
188     TOK_PARAMCOUNT,
189     TOK_PC02,
190     TOK_PROC,
191     TOK_REFERENCED,
192     TOK_RELOC,
193     TOK_REPEAT,
194     TOK_RES,
195     TOK_RIGHT,
196     TOK_RODATA,
197     TOK_SEGMENT,
198     TOK_SMART,
199     TOK_STRAT,
200     TOK_STRING,
201     TOK_STRLEN,
202     TOK_SUNPLUS,
203     TOK_TCOUNT,
204     TOK_WARNING,
205     TOK_WORD,
206     TOK_XMATCH,
207     TOK_ZEROPAGE,
208     TOK_LASTPSEUDO      = TOK_ZEROPAGE,
209
210     TOK_COUNT           /* Count of tokens */
211 };
212
213
214
215 /* Scanner variables */
216 #define MAX_INPUT_FILES 254             /* No more than this files total */
217 #define MAX_STR_LEN     255             /* Maximum length of any string */
218 extern enum Token Tok;                  /* Current token */
219 extern int WS;                          /* Flag: Whitespace before token */
220 extern long IVal;                       /* Integer token attribute */
221 extern char SVal [MAX_STR_LEN+1];       /* String token attribute */
222
223 extern FilePos  CurPos;                 /* Name and position in file */
224 extern int      ForcedEnd;              /* Force end of assembly */
225
226
227
228 /*****************************************************************************/
229 /*                                   Code                                    */
230 /*****************************************************************************/
231
232
233
234 void NewInputFile (const char* Name);
235 /* Open a new input file */
236
237 void DoneInputFile (void);
238 /* Close the current input file */
239
240 void NewInputData (const char* Data, int Malloced);
241 /* Add a chunk of input data to the input stream */
242
243 void LocaseSVal (void);
244 /* Make SVal lower case */
245
246 void UpcaseSVal (void);
247 /* Make SVal upper case */
248
249 void NextRawTok (void);
250 /* Read the next raw token from the input stream */
251
252 int TokHasSVal (enum Token Tok);
253 /* Return true if the given token has an attached SVal */
254
255 int TokHasIVal (enum Token Tok);
256 /* Return true if the given token has an attached IVal */
257
258 int GetSubKey (const char** Keys, unsigned Count);
259 /* Search for a subkey in a table of keywords. The current token must be an
260  * identifier and all keys must be in upper case. The identifier will be
261  * uppercased in the process. The function returns the index of the keyword,
262  * or -1 if the keyword was not found.
263  */
264
265 void InitScanner (const char* InFile);
266 /* Initialize the scanner, open the given input file */
267
268 void DoneScanner (void);
269 /* Release scanner resources */
270
271
272
273 /* End of scanner.h */
274
275 #endif
276
277
278