]> git.sur5r.net Git - cc65/blob - src/cc65/scanner.h
Added support for old style (K&R) function declarations.
[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_DIV_ASSIGN,
93     TOK_DIV,
94     TOK_BOOL_AND,
95     TOK_AND_ASSIGN,
96     TOK_AND,
97     TOK_NE,
98     TOK_BOOL_NOT,
99     TOK_BOOL_OR,
100     TOK_OR_ASSIGN,
101     TOK_OR,
102     TOK_EQ,
103     TOK_ASSIGN,
104     TOK_SHL_ASSIGN,
105     TOK_SHL,
106
107     /* Inequalities */
108     TOK_LE,
109     TOK_LT,
110     TOK_GE,
111     TOK_GT,
112
113     TOK_SHR_ASSIGN,
114     TOK_SHR,
115     TOK_XOR_ASSIGN,
116     TOK_XOR,
117     TOK_MOD_ASSIGN,
118     TOK_MOD,
119     TOK_QUEST,
120     TOK_COLON,
121     TOK_RPAREN,
122     TOK_SCONST,
123     TOK_ICONST,
124     TOK_CCONST,
125     TOK_FCONST,
126
127     TOK_ATTRIBUTE,
128     TOK_FASTCALL,
129     TOK_AX,
130     TOK_EAX,
131
132     TOK_PRAGMA
133 } token_t;
134
135
136
137 /*****************************************************************************/
138 /*                                   data                                    */
139 /*****************************************************************************/
140
141
142
143 /* Token stuff */
144 typedef struct Token_ Token;
145 struct Token_ {
146     token_t     Tok;            /* The token itself */
147     long        IVal;           /* The integer attribute */
148     ident       Ident;          /* Identifier if IDENT */
149     unsigned    Pos;            /* Source line where the token comes from */
150     type*       IType;          /* Type if integer constant */
151 };
152
153 extern Token CurTok;            /* The current token */
154 extern Token NextTok;           /* The next token */
155
156 /* Defines to make the old code work */
157 #define curtok  CurTok.Tok
158 #define curval  CurTok.IVal
159 #define curpos  CurTok.Pos
160 #define curtype CurTok.IType
161
162 #define nxttok  NextTok.Tok
163 #define nxtval  NextTok.IVal
164 #define nxtpos  NextTok.Pos
165 #define nxttype NextTok.IType
166
167
168
169 /*****************************************************************************/
170 /*                                   code                                    */
171 /*****************************************************************************/
172
173
174
175 void symname (char* s);
176 /* Get symbol from input stream */
177
178 int issym (char* s);
179 /* Get symbol from input stream or return 0 if not a symbol. */
180
181 void NextToken (void);                
182 /* Get next token from input stream */
183
184 void Consume (token_t Token, unsigned ErrNum);
185 /* Eat token if it is the next in the input stream, otherwise print an error
186  * message.
187  */
188
189 void ConsumeColon (void);
190 /* Check for a colon and skip it. */
191
192 void ConsumeSemi (void);
193 /* Check for a semicolon and skip it. */
194
195 void ConsumeLParen (void);
196 /* Check for a left parenthesis and skip it */
197
198 void ConsumeRParen (void);
199 /* Check for a right parenthesis and skip it */
200
201 void ConsumeLBrack (void);
202 /* Check for a left bracket and skip it */
203
204 void ConsumeRBrack (void);
205 /* Check for a right bracket and skip it */
206
207 void ConsumeLCurly (void);
208 /* Check for a left curly brace and skip it */
209
210 void ConsumeRCurly (void);
211 /* Check for a right curly brace and skip it */
212
213
214
215 /* End of scanner.h */
216 #endif
217
218
219
220
221
222