]> git.sur5r.net Git - cc65/blob - src/ca65/scanner.h
952c6bab0da5d9e6fa3dc5f2a93fca30dad58c4c
[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_DBYT,
128     TOK_DEBUGINFO,
129     TOK_DEFINE,
130     TOK_DEFINED,
131     TOK_DWORD,
132     TOK_ELSE,
133     TOK_ELSEIF,
134     TOK_END,
135     TOK_ENDIF,
136     TOK_ENDMACRO,
137     TOK_ENDPROC,
138     TOK_ENDREP,
139     TOK_ERROR,
140     TOK_EXITMACRO,
141     TOK_EXPORT,
142     TOK_EXPORTZP,
143     TOK_FARADDR,
144     TOK_FEATURE,
145     TOK_FILEOPT,
146     TOK_GLOBAL,
147     TOK_GLOBALZP,
148     TOK_I16,
149     TOK_I8,
150     TOK_IF,
151     TOK_IFBLANK,
152     TOK_IFCONST,
153     TOK_IFDEF,
154     TOK_IFNBLANK,
155     TOK_IFNCONST,
156     TOK_IFNDEF,
157     TOK_IFNREF,
158     TOK_IFP02,
159     TOK_IFP816,
160     TOK_IFPC02,
161     TOK_IFREF,
162     TOK_IMPORT,
163     TOK_IMPORTZP,
164     TOK_INCBIN,
165     TOK_INCLUDE,
166     TOK_LEFT,
167     TOK_LINECONT,
168     TOK_LIST,
169     TOK_LISTBYTES,
170     TOK_LOCAL,
171     TOK_LOCALCHAR,
172     TOK_MACPACK,
173     TOK_MACRO,
174     TOK_MATCH,
175     TOK_MID,
176     TOK_NULL,
177     TOK_ORG,
178     TOK_OUT,
179     TOK_P02,
180     TOK_P816,
181     TOK_PAGELENGTH,
182     TOK_PARAMCOUNT,
183     TOK_PC02,
184     TOK_PROC,
185     TOK_REFERENCED,
186     TOK_RELOC,
187     TOK_REPEAT,
188     TOK_RES,
189     TOK_RIGHT,
190     TOK_RODATA,
191     TOK_SEGMENT,
192     TOK_SMART,
193     TOK_STRAT,
194     TOK_STRING,
195     TOK_STRLEN,
196     TOK_SUNPLUS,
197     TOK_TCOUNT,
198     TOK_WARNING,
199     TOK_WORD,
200     TOK_XMATCH,
201     TOK_ZEROPAGE,
202     TOK_LASTPSEUDO      = TOK_ZEROPAGE,
203
204     TOK_COUNT           /* Count of tokens */
205 };
206
207
208
209 /* Scanner variables */
210 #define MAX_INPUT_FILES 254             /* No more than this files total */
211 #define MAX_STR_LEN     255             /* Maximum length of any string */
212 extern enum Token Tok;                  /* Current token */
213 extern int WS;                          /* Flag: Whitespace before token */
214 extern long IVal;                       /* Integer token attribute */
215 extern char SVal [MAX_STR_LEN+1];       /* String token attribute */
216
217 extern FilePos  CurPos;                 /* Name and position in file */
218 extern int      ForcedEnd;              /* Force end of assembly */
219
220
221
222 /*****************************************************************************/
223 /*                                   Code                                    */
224 /*****************************************************************************/
225
226
227
228 const char* GetFileName (unsigned char Name);
229 /* Get the name of a file where the name index is known */
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 UpcaseSVal (void);
241 /* Make SVal upper case */
242
243 void NextRawTok (void);
244 /* Read the next raw token from the input stream */
245
246 int TokHasSVal (enum Token Tok);
247 /* Return true if the given token has an attached SVal */
248
249 int TokHasIVal (enum Token Tok);
250 /* Return true if the given token has an attached IVal */
251
252 int GetSubKey (const char** Keys, unsigned Count);
253 /* Search for a subkey in a table of keywords. The current token must be an
254  * identifier and all keys must be in upper case. The identifier will be
255  * uppercased in the process. The function returns the index of the keyword,
256  * or -1 if the keyword was not found.
257  */
258
259 void WriteFiles (void);
260 /* Write the list of input files to the object file */
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