]> git.sur5r.net Git - cc65/blob - src/ca65/token.h
7aaba34c3315ba4a64db6d06f0f8d87a4ca104a5
[cc65] / src / ca65 / token.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  token.h                                  */
4 /*                                                                           */
5 /*                  Token list for the ca65 macro assembler                  */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2007-2012, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
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 TOKEN_H
37 #define TOKEN_H
38
39
40
41 /* common */
42 #include "filepos.h"
43 #include "inline.h"
44 #include "strbuf.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
54 /* Tokens */
55 typedef enum token_t {
56     TOK_NONE,           /* Start value, invalid */
57     TOK_EOF,            /* End of input file */
58     TOK_SEP,            /* Separator (usually newline) */
59     TOK_IDENT,          /* An identifier */
60     TOK_LOCAL_IDENT,    /* A cheap local identifier */
61
62     TOK_INTCON,         /* Integer constant */
63     TOK_CHARCON,        /* Character constant */
64     TOK_STRCON,         /* String constant */
65
66     TOK_A,              /* A)ccumulator */
67     TOK_X,              /* X register */
68     TOK_Y,              /* Y register */
69     TOK_S,              /* S register */
70     TOK_REG,            /* Sweet16 R.. register (in sweet16 mode) */
71
72     TOK_ASSIGN,         /* := */
73     TOK_ULABEL,         /* :++ or :-- */
74
75     TOK_EQ,             /* = */
76     TOK_NE,             /* <> */
77     TOK_LT,             /* < */
78     TOK_GT,             /* > */
79     TOK_LE,             /* <= */
80     TOK_GE,             /* >= */
81
82     TOK_BOOLAND,        /* .and */
83     TOK_BOOLOR,         /* .or */
84     TOK_BOOLXOR,        /* .xor */
85     TOK_BOOLNOT,        /* .not */
86
87     TOK_PLUS,           /* + */
88     TOK_MINUS,          /* - */
89     TOK_MUL,            /* * */
90     TOK_STAR = TOK_MUL, /* Alias */
91     TOK_DIV,            /* / */
92     TOK_MOD,            /* ! */
93     TOK_OR,             /* | */
94     TOK_XOR,            /* ^ */
95     TOK_AND,            /* & */
96     TOK_SHL,            /* << */
97     TOK_SHR,            /* >> */
98     TOK_NOT,            /* ~ */
99
100     TOK_PC,             /* $ if enabled */
101     TOK_NAMESPACE,      /* :: */
102     TOK_DOT,            /* . */
103     TOK_COMMA,          /* , */
104     TOK_HASH,           /* # */
105     TOK_COLON,          /* : */
106     TOK_LPAREN,         /* ( */
107     TOK_RPAREN,         /* ) */
108     TOK_LBRACK,         /* [ */
109     TOK_RBRACK,         /* ] */
110     TOK_LCURLY,         /* { */
111     TOK_RCURLY,         /* } */
112     TOK_AT,             /* @ - in Sweet16 mode */
113
114     TOK_OVERRIDE_ZP,    /* z: */
115     TOK_OVERRIDE_ABS,   /* a: */
116     TOK_OVERRIDE_FAR,   /* f: */
117
118     TOK_MACPARAM,       /* Macro parameter, not generated by scanner */
119     TOK_REPCOUNTER,     /* Repeat counter, not generated by scanner */
120
121     /* The next ones are tokens for the pseudo instructions. Keep together! */
122     TOK_FIRSTPSEUDO,
123     TOK_A16             = TOK_FIRSTPSEUDO,
124     TOK_A8,
125     TOK_ADDR,
126     TOK_ADDRSIZE,
127     TOK_ALIGN,
128     TOK_ASCIIZ,
129     TOK_ASSERT,
130     TOK_AUTOIMPORT,
131     TOK_BANK,
132     TOK_BANKBYTE,
133     TOK_BANKBYTES,
134     TOK_BLANK,
135     TOK_BSS,
136     TOK_BYTE,
137     TOK_CASE,
138     TOK_CHARMAP,
139     TOK_CODE,
140     TOK_CONCAT,
141     TOK_CONDES,
142     TOK_CONST,
143     TOK_CONSTRUCTOR,
144     TOK_CPU,
145     TOK_DATA,
146     TOK_DBG,
147     TOK_DBYT,
148     TOK_DEBUGINFO,
149     TOK_DEFINE,
150     TOK_DEFINED,
151     TOK_DELMAC,
152     TOK_DESTRUCTOR,
153     TOK_DWORD,
154     TOK_ELSE,
155     TOK_ELSEIF,
156     TOK_END,
157     TOK_ENDENUM,
158     TOK_ENDIF,
159     TOK_ENDMACRO,
160     TOK_ENDPROC,
161     TOK_ENDREP,
162     TOK_ENDSCOPE,
163     TOK_ENDSTRUCT,
164     TOK_ENDUNION,
165     TOK_ENUM,
166     TOK_ERROR,
167     TOK_EXITMACRO,
168     TOK_EXPORT,
169     TOK_EXPORTZP,
170     TOK_FARADDR,
171     TOK_FATAL,
172     TOK_FEATURE,
173     TOK_FILEOPT,
174     TOK_FORCEIMPORT,
175     TOK_FORCEWORD,
176     TOK_GLOBAL,
177     TOK_GLOBALZP,
178     TOK_HIBYTE,
179     TOK_HIBYTES,
180     TOK_HIWORD,
181     TOK_I16,
182     TOK_I8,
183     TOK_MAKEIDENT,
184     TOK_IF,
185     TOK_IFBLANK,
186     TOK_IFCONST,
187     TOK_IFDEF,
188     TOK_IFNBLANK,
189     TOK_IFNCONST,
190     TOK_IFNDEF,
191     TOK_IFNREF,
192     TOK_IFP02,
193     TOK_IFP816,
194     TOK_IFPC02,
195     TOK_IFPSC02,
196     TOK_IFREF,
197     TOK_IMPORT,
198     TOK_IMPORTZP,
199     TOK_INCBIN,
200     TOK_INCLUDE,
201     TOK_INTERRUPTOR,
202     TOK_LEFT,
203     TOK_LINECONT,
204     TOK_LIST,
205     TOK_LISTBYTES,
206     TOK_LOBYTE,
207     TOK_LOBYTES,
208     TOK_LOCAL,
209     TOK_LOCALCHAR,
210     TOK_LOWORD,
211     TOK_MACPACK,
212     TOK_MACRO,
213     TOK_MATCH,
214     TOK_MAX,
215     TOK_MID,
216     TOK_MIN,
217     TOK_NULL,
218     TOK_ORG,
219     TOK_OUT,
220     TOK_P02,
221     TOK_P816,
222     TOK_PAGELENGTH,
223     TOK_PARAMCOUNT,
224     TOK_PC02,
225     TOK_POPCPU,
226     TOK_POPSEG,
227     TOK_PROC,
228     TOK_PSC02,
229     TOK_PUSHCPU,
230     TOK_PUSHSEG,
231     TOK_REFERENCED,
232     TOK_RELOC,
233     TOK_REPEAT,
234     TOK_RES,
235     TOK_RIGHT,
236     TOK_RODATA,
237     TOK_SCOPE,
238     TOK_SEGMENT,
239     TOK_SET,
240     TOK_SETCPU,
241     TOK_SIZEOF,
242     TOK_SMART,
243     TOK_SPRINTF,
244     TOK_STRAT,
245     TOK_STRING,
246     TOK_STRLEN,
247     TOK_STRUCT,
248     TOK_TAG,
249     TOK_TCOUNT,
250     TOK_TIME,
251     TOK_UNDEF,
252     TOK_UNION,
253     TOK_VERSION,
254     TOK_WARNING,
255     TOK_WORD,
256     TOK_XMATCH,
257     TOK_ZEROPAGE,
258     TOK_LASTPSEUDO      = TOK_ZEROPAGE,
259
260     TOK_COUNT           /* Count of tokens */
261 } token_t;
262
263
264
265 /* Complete token including attributes and flags */
266 typedef struct Token Token;
267 struct Token {
268     token_t     Tok;            /* The actual token value */
269     int         WS;             /* Flag for "whitespace before token" */
270     long        IVal;           /* Integer attribute value */
271     StrBuf      SVal;           /* String attribute value */
272     FilePos     Pos;            /* Position from which token was read */
273 };
274
275 /* Initializer value for a token */
276 #define STATIC_TOKEN_INITIALIZER {      \
277     TOK_NONE,                           \
278     0,                                  \
279     0,                                  \
280     STATIC_STRBUF_INITIALIZER,          \
281     STATIC_FILEPOS_INITIALIZER          \
282 }
283
284
285
286 /*****************************************************************************/
287 /*                                   Code                                    */
288 /*****************************************************************************/
289
290
291
292 int TokHasSVal (token_t Tok);
293 /* Return true if the given token has an attached SVal */
294
295 int TokHasIVal (token_t Tok);
296 /* Return true if the given token has an attached IVal */
297
298 #if defined(HAVE_INLINE)
299 INLINE int TokIsSep (enum token_t T)
300 /* Return true if this is a separator token */
301 {
302     return (T == TOK_SEP || T == TOK_EOF);
303 }
304 #else
305 #  define TokIsSep(T)   ((T) == TOK_SEP || (T) == TOK_EOF)
306 #endif
307
308 void CopyToken (Token* Dst, const Token* Src);
309 /* Copy a token. The current value of Dst.SVal is free'd, so Dst must be
310 ** initialized.
311 */
312
313
314
315 /* End of token.h */
316
317 #endif