]> git.sur5r.net Git - cc65/blob - src/cc65/scanner.h
a707e4d1492364d31ce4534c221eb2bf147cd995
[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_FAR,
129     TOK_FASTCALL,
130     TOK_AX,
131     TOK_EAX,
132             
133     TOK_PRAGMA
134 } token_t;
135
136
137
138 /*****************************************************************************/
139 /*                                   data                                    */
140 /*****************************************************************************/
141
142
143
144 /* Token stuff */
145 typedef struct Token_ Token;
146 struct Token_ {
147     token_t     Tok;            /* The token itself */
148     long        IVal;           /* The integer attribute */
149     ident       Ident;          /* Identifier if IDENT */
150     unsigned    Pos;            /* Source line where the token comes from */
151     type*       IType;          /* Type if integer constant */
152 };
153
154 extern Token CurTok;            /* The current token */
155 extern Token NextTok;           /* The next token */
156
157 /* Defines to make the old code work */
158 #define curtok  CurTok.Tok
159 #define curval  CurTok.IVal
160 #define curpos  CurTok.Pos
161 #define curtype CurTok.IType
162
163 #define nxttok  NextTok.Tok
164 #define nxtval  NextTok.IVal
165 #define nxtpos  NextTok.Pos
166 #define nxttype NextTok.IType
167
168
169
170 /*****************************************************************************/
171 /*                                   code                                    */
172 /*****************************************************************************/
173
174
175
176 void SymName (char* s);
177 /* Get symbol from input stream */
178
179 int IsSym (char* s);
180 /* Get symbol from input stream or return 0 if not a symbol. */
181
182 void NextToken (void);
183 /* Get next token from input stream */
184
185 void Consume (token_t Token, unsigned ErrNum);
186 /* Eat token if it is the next in the input stream, otherwise print an error
187  * message.
188  */
189
190 void ConsumeColon (void);
191 /* Check for a colon and skip it. */
192
193 void ConsumeSemi (void);
194 /* Check for a semicolon and skip it. */
195
196 void ConsumeLParen (void);
197 /* Check for a left parenthesis and skip it */
198
199 void ConsumeRParen (void);
200 /* Check for a right parenthesis and skip it */
201
202 void ConsumeLBrack (void);
203 /* Check for a left bracket and skip it */
204
205 void ConsumeRBrack (void);
206 /* Check for a right bracket and skip it */
207
208 void ConsumeLCurly (void);
209 /* Check for a left curly brace and skip it */
210
211 void ConsumeRCurly (void);
212 /* Check for a right curly brace and skip it */
213
214
215
216 /* End of scanner.h */
217 #endif
218
219
220
221
222
223