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 */
59 TOK_FIRST_STORAGE_CLASS,
60 TOK_AUTO = TOK_FIRST_STORAGE_CLASS,
65 TOK_LAST_STORAGE_CLASS = TOK_TYPEDEF,
67 /* Tokens denoting type qualifiers */
69 TOK_CONST = TOK_FIRST_TYPEQUAL,
72 TOK_LAST_TYPEQUAL = TOK_RESTRICT,
74 /* Function specifiers */
78 /* Tokens denoting types */
80 TOK_ENUM = TOK_FIRST_TYPE,
92 TOK_LAST_TYPE = TOK_VOID,
94 /* Control statements */
115 /* Primary operators */
134 TOK_MUL = TOK_STAR, /* Alias */
184 /*****************************************************************************/
186 /*****************************************************************************/
191 typedef struct Token Token;
193 token_t Tok; /* The token itself */
194 long IVal; /* The integer attribute */
195 double FVal; /* The float attribute */
196 ident Ident; /* Identifier if IDENT */
197 LineInfo* LI; /* Source line where the token comes from */
198 Type* Type; /* Type if integer or float constant */
201 extern Token CurTok; /* The current token */
202 extern Token NextTok; /* The next token */
206 /*****************************************************************************/
208 /*****************************************************************************/
212 #if defined(HAVE_INLINE)
213 INLINE int TokIsStorageClass (const Token* T)
214 /* Return true if the token is a storage class specifier */
216 return (T->Tok >= TOK_FIRST_STORAGE_CLASS && T->Tok <= TOK_LAST_STORAGE_CLASS);
219 # define TokIsStorageClass(T) \
220 ((T)->Tok >= TOK_FIRST_STORAGE_CLASS && (T)->Tok <= TOK_LAST_STORAGE_CLASS)
223 #if defined(HAVE_INLINE)
224 INLINE int TokIsType (const Token* T)
225 /* Return true if the token is a type */
227 return (T->Tok >= TOK_FIRST_TYPE && T->Tok <= TOK_LAST_TYPE);
230 # define TokIsType(T) ((T)->Tok >= TOK_FIRST_TYPE && (T)->Tok <= TOK_LAST_TYPE)
233 #if defined(HAVE_INLINE)
234 INLINE int TokIsTypeQual (const Token* T)
235 /* Return true if the token is a type qualifier */
237 return (T->Tok >= TOK_FIRST_TYPEQUAL && T->Tok <= TOK_LAST_TYPEQUAL);
240 # define TokIsTypeQual(T) ((T)->Tok >= TOK_FIRST_TYPEQUAL && (T)->Tok <= TOK_LAST_TYPEQUAL)
243 int TokIsFuncSpec (const Token* T);
244 /* Return true if the token is a function specifier */
246 void SymName (char* S);
247 /* Read a symbol from the input stream. The first character must have been
248 * checked before calling this function. The buffer is expected to be at
249 * least of size MAX_IDENTLEN+1.
253 /* If a symbol follows, read it and return 1, otherwise return 0 */
255 void NextToken (void);
256 /* Get next token from input stream */
258 void SkipTokens (const token_t* TokenList, unsigned TokenCount);
259 /* Skip tokens until we reach TOK_CEOF or a token in the given token list.
260 * This routine is used for error recovery.
263 int Consume (token_t Token, const char* ErrorMsg);
264 /* Eat token if it is the next in the input stream, otherwise print an error
265 * message. Returns true if the token was found and false otherwise.
268 int ConsumeColon (void);
269 /* Check for a colon and skip it. */
271 int ConsumeSemi (void);
272 /* Check for a semicolon and skip it. */
274 int ConsumeComma (void);
275 /* Check for a comma and skip it. */
277 int ConsumeLParen (void);
278 /* Check for a left parenthesis and skip it */
280 int ConsumeRParen (void);
281 /* Check for a right parenthesis and skip it */
283 int ConsumeLBrack (void);
284 /* Check for a left bracket and skip it */
286 int ConsumeRBrack (void);
287 /* Check for a right bracket and skip it */
289 int ConsumeLCurly (void);
290 /* Check for a left curly brace and skip it */
292 int ConsumeRCurly (void);
293 /* Check for a right curly brace and skip it */
297 /* End of scanner.h */