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