1 /*****************************************************************************/
5 /* Source file line info structure */
9 /* (C) 1998-2010, Ullrich von Bassewitz */
10 /* Roemerstrasse 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 /*****************************************************************************/
51 /*****************************************************************************/
52 /* Token definitions */
53 /*****************************************************************************/
57 typedef enum token_t {
61 /* Storage specifiers */
62 TOK_FIRST_STORAGE_CLASS,
63 TOK_AUTO = TOK_FIRST_STORAGE_CLASS,
68 TOK_LAST_STORAGE_CLASS = TOK_TYPEDEF,
70 /* Tokens denoting type qualifiers */
72 TOK_CONST = TOK_FIRST_TYPEQUAL,
75 TOK_LAST_TYPEQUAL = TOK_RESTRICT,
77 /* Function specifiers */
82 /* Tokens denoting types */
84 TOK_ENUM = TOK_FIRST_TYPE,
96 TOK_LAST_TYPE = TOK_VOID,
98 /* Control statements */
119 /* Primary operators */
138 TOK_MUL = TOK_STAR, /* Alias */
189 /*****************************************************************************/
191 /*****************************************************************************/
195 /* Forward for struct Literal */
199 typedef struct Token Token;
201 token_t Tok; /* The token itself */
202 long IVal; /* The integer attribute */
203 Double FVal; /* The float attribute */
204 struct Literal* SVal; /* String literal is any */
205 ident Ident; /* Identifier if IDENT */
206 LineInfo* LI; /* Source line where the token comes from */
207 Type* Type; /* Type if integer or float constant */
210 extern Token CurTok; /* The current token */
211 extern Token NextTok; /* The next token */
215 /*****************************************************************************/
217 /*****************************************************************************/
221 #if defined(HAVE_INLINE)
222 INLINE int TokIsStorageClass (const Token* T)
223 /* Return true if the token is a storage class specifier */
225 return (T->Tok >= TOK_FIRST_STORAGE_CLASS && T->Tok <= TOK_LAST_STORAGE_CLASS);
228 # define TokIsStorageClass(T) \
229 ((T)->Tok >= TOK_FIRST_STORAGE_CLASS && (T)->Tok <= TOK_LAST_STORAGE_CLASS)
232 #if defined(HAVE_INLINE)
233 INLINE int TokIsType (const Token* T)
234 /* Return true if the token is a type */
236 return (T->Tok >= TOK_FIRST_TYPE && T->Tok <= TOK_LAST_TYPE);
239 # define TokIsType(T) ((T)->Tok >= TOK_FIRST_TYPE && (T)->Tok <= TOK_LAST_TYPE)
242 #if defined(HAVE_INLINE)
243 INLINE int TokIsTypeQual (const Token* T)
244 /* Return true if the token is a type qualifier */
246 return (T->Tok >= TOK_FIRST_TYPEQUAL && T->Tok <= TOK_LAST_TYPEQUAL);
249 # define TokIsTypeQual(T) ((T)->Tok >= TOK_FIRST_TYPEQUAL && (T)->Tok <= TOK_LAST_TYPEQUAL)
252 int TokIsFuncSpec (const Token* T);
253 /* Return true if the token is a function specifier */
255 void SymName (char* S);
256 /* Read a symbol from the input stream. The first character must have been
257 * checked before calling this function. The buffer is expected to be at
258 * least of size MAX_IDENTLEN+1.
262 /* If a symbol follows, read it and return 1, otherwise return 0 */
264 void NextToken (void);
265 /* Get next token from input stream */
267 void SkipTokens (const token_t* TokenList, unsigned TokenCount);
268 /* Skip tokens until we reach TOK_CEOF or a token in the given token list.
269 * This routine is used for error recovery.
272 int Consume (token_t Token, const char* ErrorMsg);
273 /* Eat token if it is the next in the input stream, otherwise print an error
274 * message. Returns true if the token was found and false otherwise.
277 int ConsumeColon (void);
278 /* Check for a colon and skip it. */
280 int ConsumeSemi (void);
281 /* Check for a semicolon and skip it. */
283 int ConsumeComma (void);
284 /* Check for a comma and skip it. */
286 int ConsumeLParen (void);
287 /* Check for a left parenthesis and skip it */
289 int ConsumeRParen (void);
290 /* Check for a right parenthesis and skip it */
292 int ConsumeLBrack (void);
293 /* Check for a left bracket and skip it */
295 int ConsumeRBrack (void);
296 /* Check for a right bracket and skip it */
298 int ConsumeLCurly (void);
299 /* Check for a left curly brace and skip it */
301 int ConsumeRCurly (void);
302 /* Check for a right curly brace and skip it */
306 /* End of scanner.h */