1 /*****************************************************************************/
5 /* Source file line info structure */
9 /* (C) 1998-2004 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
48 /*****************************************************************************/
49 /* Token definitions */
50 /*****************************************************************************/
54 typedef enum token_t {
58 /* Storage specifiers */
65 /* Tokens denoting type qualifiers */
67 TOK_CONST = TOK_FIRST_TYPEQUAL,
70 TOK_LAST_TYPEQUAL = TOK_RESTRICT,
72 /* Function specifiers */
75 /* Tokens denoting types */
77 TOK_ENUM = TOK_FIRST_TYPE,
89 TOK_LAST_TYPE = TOK_VOID,
91 /* Control statements */
112 /* Primary operators */
131 TOK_MUL = TOK_STAR, /* Alias */
182 /*****************************************************************************/
184 /*****************************************************************************/
189 typedef struct Token Token;
191 token_t Tok; /* The token itself */
192 long IVal; /* The integer attribute */
193 double FVal; /* The float attribute */
194 ident Ident; /* Identifier if IDENT */
195 LineInfo* LI; /* Source line where the token comes from */
196 type* Type; /* Type if integer or float constant */
199 extern Token CurTok; /* The current token */
200 extern Token NextTok; /* The next token */
204 /*****************************************************************************/
206 /*****************************************************************************/
210 #if defined(HAVE_INLINE)
211 INLINE int TokIsType (const Token* T)
212 /* Return true if the token is a type */
214 return (T->Tok >= TOK_FIRST_TYPE && T->Tok <= TOK_LAST_TYPE);
217 # define TokIsType(T) ((T)->Tok >= TOK_FIRST_TYPE && (T)->Tok <= TOK_LAST_TYPE)
220 #if defined(HAVE_INLINE)
221 INLINE int TokIsTypeQual (const Token* T)
222 /* Return true if the token is a type qualifier */
224 return (T->Tok >= TOK_FIRST_TYPEQUAL && T->Tok <= TOK_LAST_TYPEQUAL);
227 # define TokIsTypeQual(T) ((T)->Tok >= TOK_FIRST_TYPEQUAL && (T)->Tok <= TOK_LAST_TYPEQUAL)
230 void SymName (char* S);
231 /* Read a symbol from the input stream. The first character must have been
232 * checked before calling this function. The buffer is expected to be at
233 * least of size MAX_IDENTLEN+1.
237 /* If a symbol follows, read it and return 1, otherwise return 0 */
239 void NextToken (void);
240 /* Get next token from input stream */
242 void SkipTokens (const token_t* TokenList, unsigned TokenCount);
243 /* Skip tokens until we reach TOK_CEOF or a token in the given token list.
244 * This routine is used for error recovery.
247 int Consume (token_t Token, const char* ErrorMsg);
248 /* Eat token if it is the next in the input stream, otherwise print an error
249 * message. Returns true if the token was found and false otherwise.
252 int ConsumeColon (void);
253 /* Check for a colon and skip it. */
255 int ConsumeSemi (void);
256 /* Check for a semicolon and skip it. */
258 int ConsumeComma (void);
259 /* Check for a comma and skip it. */
261 int ConsumeLParen (void);
262 /* Check for a left parenthesis and skip it */
264 int ConsumeRParen (void);
265 /* Check for a right parenthesis and skip it */
267 int ConsumeLBrack (void);
268 /* Check for a left bracket and skip it */
270 int ConsumeRBrack (void);
271 /* Check for a right bracket and skip it */
273 int ConsumeLCurly (void);
274 /* Check for a left curly brace and skip it */
276 int ConsumeRCurly (void);
277 /* Check for a right curly brace and skip it */
281 /* End of scanner.h */