]> git.sur5r.net Git - cc65/blob - src/cc65/scanner.h
Moved verbose output to a shared module in the common/ directory.
[cc65] / src / cc65 / scanner.h
1 /*
2  * scanner.h
3  *
4  * Ullrich von Bassewitz, 07.06.1998
5  */
6
7
8
9 #ifndef SCANNER_H
10 #define SCANNER_H
11
12
13
14 #include "datatype.h"
15 #include "ident.h"
16
17
18
19 /*****************************************************************************/
20 /*                             Token definitions                             */
21 /*****************************************************************************/
22
23
24
25 typedef enum token_t {
26     TOK_CEOF,
27
28     TOK_AUTO,
29     TOK_EXTERN,
30     TOK_REGISTER,
31     TOK_STATIC,
32     TOK_TYPEDEF,
33     TOK_ENUM,
34     TOK_CONST,
35     TOK_VOLATILE,
36
37     /* Tokens denoting types */
38     TOK_FIRSTTYPE,
39     TOK_CHAR            = TOK_FIRSTTYPE,
40     TOK_INT,
41     TOK_DOUBLE,
42     TOK_FLOAT,
43     TOK_LONG,
44     TOK_UNSIGNED,
45     TOK_SIGNED,
46     TOK_SHORT,
47     TOK_STRUCT,
48     TOK_UNION,
49     TOK_VOID,
50     TOK_LASTTYPE        = TOK_VOID,
51
52     /* Control statements */
53     TOK_DO,
54     TOK_FOR,
55     TOK_GOTO,
56     TOK_IF,
57     TOK_RETURN,
58     TOK_SWITCH,
59     TOK_WHILE,
60
61     TOK_ASM,
62     TOK_CASE,
63     TOK_DEFAULT,
64     TOK_BREAK,
65     TOK_CONTINUE,
66     TOK_ELSE,
67     TOK_ELLIPSIS,
68     TOK_SIZEOF,
69
70     TOK_IDENT,
71     TOK_SEMI,
72
73     /* Primary operators */
74     TOK_LBRACK,
75     TOK_LPAREN,
76     TOK_DOT,
77     TOK_PTR_REF,
78
79     TOK_LCURLY,
80     TOK_RBRACK,
81     TOK_COMP,
82     TOK_INC,
83     TOK_PLUS_ASSIGN,
84     TOK_PLUS,
85     TOK_COMMA,
86     TOK_DEC,
87     TOK_MINUS_ASSIGN,
88     TOK_RCURLY,
89     TOK_MINUS,
90     TOK_MUL_ASSIGN,
91     TOK_STAR,
92     TOK_MUL = TOK_STAR,         /* Alias */
93     TOK_DIV_ASSIGN,
94     TOK_DIV,
95     TOK_BOOL_AND,
96     TOK_AND_ASSIGN,
97     TOK_AND,
98     TOK_NE,
99     TOK_BOOL_NOT,
100     TOK_BOOL_OR,
101     TOK_OR_ASSIGN,
102     TOK_OR,
103     TOK_EQ,
104     TOK_ASSIGN,
105
106     /* Inequalities */
107     TOK_LE,
108     TOK_LT,
109     TOK_GE,
110     TOK_GT,
111
112     TOK_SHL_ASSIGN,
113     TOK_SHL,
114     TOK_SHR_ASSIGN,
115     TOK_SHR,
116     TOK_XOR_ASSIGN,
117     TOK_XOR,
118     TOK_MOD_ASSIGN,
119     TOK_MOD,
120     TOK_QUEST,
121     TOK_COLON,
122     TOK_RPAREN,
123     TOK_SCONST,
124     TOK_ICONST,
125     TOK_CCONST,
126     TOK_FCONST,
127
128     TOK_ATTRIBUTE,
129     TOK_FAR,
130     TOK_FASTCALL,
131     TOK_A,
132     TOK_X,
133     TOK_Y,
134     TOK_AX,
135     TOK_EAX,
136
137     TOK_PRAGMA
138 } token_t;
139
140
141
142 /*****************************************************************************/
143 /*                                   data                                    */
144 /*****************************************************************************/
145
146
147
148 /* Token stuff */
149 typedef struct Token_ Token;
150 struct Token_ {
151     token_t     Tok;            /* The token itself */
152     long        IVal;           /* The integer attribute */
153     double      FVal;           /* The float attribute */
154     ident       Ident;          /* Identifier if IDENT */
155     unsigned    Pos;            /* Source line where the token comes from */
156     type*       Type;           /* Type if integer or float constant */
157 };
158
159 extern Token CurTok;            /* The current token */
160 extern Token NextTok;           /* The next token */
161
162 /* Defines to make the old code work */
163 #define curtok  CurTok.Tok
164 #define curval  CurTok.IVal
165 #define curpos  CurTok.Pos
166 #define curtype CurTok.Type
167
168 #define nxttok  NextTok.Tok
169 #define nxtval  NextTok.IVal
170 #define nxtpos  NextTok.Pos
171 #define nxttype NextTok.Type
172
173
174
175 /*****************************************************************************/
176 /*                                   code                                    */
177 /*****************************************************************************/
178
179
180
181 void SymName (char* s);
182 /* Get symbol from input stream */
183
184 int IsSym (char* s);
185 /* Get symbol from input stream or return 0 if not a symbol. */
186
187 void NextToken (void);
188 /* Get next token from input stream */
189
190 void Consume (token_t Token, const char* ErrorMsg);
191 /* Eat token if it is the next in the input stream, otherwise print an error
192  * message.
193  */
194
195 void ConsumeColon (void);
196 /* Check for a colon and skip it. */
197
198 void ConsumeSemi (void);
199 /* Check for a semicolon and skip it. */
200
201 void ConsumeComma (void);
202 /* Check for a comma and skip it. */
203
204 void ConsumeLParen (void);
205 /* Check for a left parenthesis and skip it */
206
207 void ConsumeRParen (void);
208 /* Check for a right parenthesis and skip it */
209
210 void ConsumeLBrack (void);
211 /* Check for a left bracket and skip it */
212
213 void ConsumeRBrack (void);
214 /* Check for a right bracket and skip it */
215
216 void ConsumeLCurly (void);
217 /* Check for a left curly brace and skip it */
218
219 void ConsumeRCurly (void);
220 /* Check for a right curly brace and skip it */
221
222
223
224 /* End of scanner.h */
225 #endif
226
227
228
229
230
231