#include "ast.h"
#include "symbol.h"
-#include "lexer_t.h"
+#include "token_t.h"
#include "type.h"
#include "adt/obst.h"
};
struct reference_expression_t {
- expression_t expression;
- symbol_t *symbol;
- union {
- declaration_t *declaration;
- } r;
+ expression_t expression;
+ symbol_t *symbol;
+ declaration_t *declaration;
};
struct call_argument_t {
#include <config.h>
-#include "lexer_t.h"
+#include "lexer.h"
#include "token_t.h"
#include "symbol_table_t.h"
#include "adt/error.h"
+#include "adt/strset.h"
#include <assert.h>
#include <errno.h>
//#define DEBUG_CHARS
#define MAX_PUTBACK 3
-static int c;
-source_position_t source_position;
-static FILE *input;
-static char buf[1027];
-static const char *bufend;
-static const char *bufpos;
-static strset_t stringset;
-//static FILE **input_stack;
-//static char **buf_stack;
+static int c;
+token_t lexer_token;
+static FILE *input;
+static char buf[1024 + MAX_PUTBACK];
+static const char *bufend;
+static const char *bufpos;
+static strset_t stringset;
+//static FILE **input_stack;
+//static char **buf_stack;
static
void error_prefix_at(const char *input_name, unsigned linenr)
}
static
-void error_prefix()
+void error_prefix(void)
{
- error_prefix_at(source_position.input_name, source_position.linenr);
+ error_prefix_at(lexer_token.source_position.input_name,
+ lexer_token.source_position.linenr);
}
static
}
static inline
-void next_char()
+void next_char(void)
{
bufpos++;
if(bufpos >= bufend) {
next_char(); \
if(c == '\n') \
next_char(); \
- source_position.linenr++; \
+ lexer_token.source_position.linenr++; \
newline_code; \
} else if(c == '\n') { \
next_char(); \
- source_position.linenr++; \
+ lexer_token.source_position.linenr++; \
newline_code; \
}
case '9':
static
-void parse_symbol(token_t *token)
+void parse_symbol(void)
{
symbol_t *symbol;
char *string;
string = obstack_finish(&symbol_obstack);
symbol = symbol_table_insert(string);
- token->type = symbol->ID;
- token->v.symbol = symbol;
+ lexer_token.type = symbol->ID;
+ lexer_token.v.symbol = symbol;
if(symbol->string != string) {
obstack_free(&symbol_obstack, string);
}
static
-void parse_number_hex(token_t *token)
+void parse_number_hex(void)
{
assert(c == 'x' || c == 'X');
next_char();
!('A' <= c && c <= 'F') &&
!('a' <= c && c <= 'f')) {
parse_error("premature end of hex number literal");
- token->type = T_ERROR;
+ lexer_token.type = T_ERROR;
return;
}
} else if ('a' <= c && c <= 'f') {
value = 16 * value + c - 'a' + 10;
} else {
- token->type = T_INTEGER;
- token->v.intvalue = value;
+ lexer_token.type = T_INTEGER;
+ lexer_token.v.intvalue = value;
return;
}
next_char();
}
static
-void parse_number_oct(token_t *token)
+void parse_number_oct(void)
{
assert(c == 'o' || c == 'O');
next_char();
if ('0' <= c && c <= '7') {
value = 8 * value + c - '0';
} else {
- token->type = T_INTEGER;
- token->v.intvalue = value;
+ lexer_token.type = T_INTEGER;
+ lexer_token.v.intvalue = value;
return;
}
next_char();
}
static
-void parse_number_dec(token_t *token, int first_char)
+void parse_number_dec(int first_char)
{
int value = 0;
if(first_char > 0) {
if (isdigit(c)) {
value = 10 * value + c - '0';
} else {
- token->type = T_INTEGER;
- token->v.intvalue = value;
+ lexer_token.type = T_INTEGER;
+ lexer_token.v.intvalue = value;
return;
}
next_char();
}
static
-void parse_number(token_t *token)
+void parse_number(void)
{
// TODO check for overflow
// TODO check for various invalid inputs sequences
next_char();
switch (c) {
case 'X':
- case 'x': parse_number_hex(token); break;
+ case 'x': parse_number_hex(); break;
case 'o':
- case 'O': parse_number_oct(token); break;
- default: parse_number_dec(token, '0');
+ case 'O': parse_number_oct(); break;
+ default: parse_number_dec('0');
}
} else {
- parse_number_dec(token, 0);
+ parse_number_dec(0);
}
}
static
-int parse_escape_sequence()
+int parse_escape_sequence(void)
{
while(1) {
int ec = c;
}
static
-void parse_string_literal(token_t *token)
+void parse_string_literal(void)
{
- unsigned start_linenr = source_position.linenr;
+ unsigned start_linenr = lexer_token.source_position.linenr;
char *string;
const char *result;
break;
case EOF:
- error_prefix_at(source_position.input_name, start_linenr);
+ error_prefix_at(lexer_token.source_position.input_name,
+ start_linenr);
fprintf(stderr, "string has no end\n");
- token->type = T_ERROR;
+ lexer_token.type = T_ERROR;
return;
case '"':
obstack_free(&symbol_obstack, string);
}
- token->type = T_STRING_LITERAL;
- token->v.string = result;
+ lexer_token.type = T_STRING_LITERAL;
+ lexer_token.v.string = result;
}
-#define MATCH_NEWLINE(code) \
- case '\r': \
- next_char(); \
- if(c == '\n') { \
- next_char(); \
- } \
- source_position.linenr++; \
- code; \
- case '\n': \
- next_char(); \
- source_position.linenr++; \
+#define MATCH_NEWLINE(code) \
+ case '\r': \
+ next_char(); \
+ if(c == '\n') { \
+ next_char(); \
+ } \
+ lexer_token.source_position.linenr++; \
+ code; \
+ case '\n': \
+ next_char(); \
+ lexer_token.source_position.linenr++; \
code;
static
-void parse_character_constant(token_t *token)
+void parse_character_constant(void)
{
assert(c == '\'');
next_char();
case EOF:
parse_error("EOF while parsing character constant");
- token->type = T_ERROR;
+ lexer_token.type = T_ERROR;
return;
default:
}
end_of_char_constant:
- token->type = T_INTEGER;
- token->v.intvalue = found_char;
+ lexer_token.type = T_INTEGER;
+ lexer_token.v.intvalue = found_char;
}
static
void skip_multiline_comment(void)
{
- unsigned start_linenr = source_position.linenr;
+ unsigned start_linenr = lexer_token.source_position.linenr;
int had_star = 0;
while(1) {
MATCH_NEWLINE(had_star = 0; break;)
case EOF:
- error_prefix_at(source_position.input_name, start_linenr);
+ error_prefix_at(lexer_token.source_position.input_name,
+ start_linenr);
fprintf(stderr, "at end of file while looking for comment end\n");
return;
default:
next_char();
if(c == '\n') {
next_char();
- source_position.linenr++;
+ lexer_token.source_position.linenr++;
}
break;
static inline
void next_pp_token(void)
{
- lexer_next_preprocessing_token(&pp_token);
+ lexer_next_preprocessing_token();
+ pp_token = lexer_token;
}
static
static
void define_directive(void)
{
- token_t temptoken;
-
- lexer_next_preprocessing_token(&temptoken);
- if(temptoken.type != T_IDENTIFIER) {
+ lexer_next_preprocessing_token();
+ if(lexer_token.type != T_IDENTIFIER) {
parse_error("expected identifier after #define\n");
eat_until_newline();
}
void ifdef_directive(int is_ifndef)
{
(void) is_ifndef;
- token_t temptoken;
- lexer_next_preprocessing_token(&temptoken);
+ lexer_next_preprocessing_token();
//expect_identifier();
//extect_newline();
}
if(pp_token.type != T_INTEGER) {
parse_error("expected integer");
} else {
- source_position.linenr = pp_token.v.intvalue - 1;
+ lexer_token.source_position.linenr = pp_token.v.intvalue - 1;
next_pp_token();
}
if(pp_token.type == T_STRING_LITERAL) {
- source_position.input_name = pp_token.v.string;
+ lexer_token.source_position.input_name = pp_token.v.string;
next_pp_token();
}
#define MAYBE(ch, set_type) \
case ch: \
next_char(); \
- token->type = set_type; \
+ lexer_token.type = set_type; \
return;
#define ELSE_CODE(code) \
#define ELSE(set_type) \
ELSE_CODE( \
- token->type = set_type; \
+ lexer_token.type = set_type; \
return; \
)
-void lexer_next_preprocessing_token(token_t *token)
+void lexer_next_preprocessing_token(void)
{
while(1) {
switch(c) {
break;
MATCH_NEWLINE(
- token->type = '\n';
+ lexer_token.type = '\n';
return;
)
SYMBOL_CHARS
- parse_symbol(token);
+ parse_symbol();
return;
DIGITS
- parse_number(token);
+ parse_number();
return;
case '"':
- parse_string_literal(token);
+ parse_string_literal();
return;
case '\'':
- parse_character_constant(token);
+ parse_character_constant();
return;
case '\\':
next_char();
if(c == '\n') {
next_char();
- source_position.linenr++;
+ lexer_token.source_position.linenr++;
break;
} else {
parse_error("unexpected '\\' found");
- token->type = T_ERROR;
+ lexer_token.type = T_ERROR;
}
return;
ELSE_CODE(
put_back(c);
c = '.';
- token->type = '.';
+ lexer_token.type = '.';
return;
)
ELSE('.')
case '*':
next_char();
skip_multiline_comment();
- lexer_next_preprocessing_token(token);
+ lexer_next_preprocessing_token();
return;
case '/':
next_char();
skip_line_comment();
- lexer_next_preprocessing_token(token);
+ lexer_next_preprocessing_token();
return;
ELSE('/')
case '%':
ELSE_CODE(
put_back(c);
c = '%';
- token->type = T_PERCENTCOLON;
+ lexer_token.type = T_PERCENTCOLON;
return;
)
ELSE(T_PERCENTCOLON)
next_char();
/* just a simple ? */
if(c != '?') {
- token->type = '?';
+ lexer_token.type = '?';
return;
}
/* might be a trigraph */
}
put_back(c);
c = '?';
- token->type = '?';
+ lexer_token.type = '?';
return;
case '[':
case '~':
case ';':
case ',':
- token->type = c;
+ lexer_token.type = c;
next_char();
return;
case EOF:
- token->type = T_EOF;
+ lexer_token.type = T_EOF;
return;
default:
next_char();
error_prefix();
fprintf(stderr, "unknown character '%c' found\n", c);
- token->type = T_ERROR;
+ lexer_token.type = T_ERROR;
return;
}
}
}
-void lexer_next_token(token_t *token)
+void lexer_next_token(void)
{
- lexer_next_preprocessing_token(token);
- if(token->type != '\n')
+ lexer_next_preprocessing_token();
+ if(lexer_token.type != '\n')
return;
newline_found:
do {
- lexer_next_preprocessing_token(token);
- } while(token->type == '\n');
+ lexer_next_preprocessing_token();
+ } while(lexer_token.type == '\n');
- if(token->type == '#') {
+ if(lexer_token.type == '#') {
parse_preprocessor_directive();
goto newline_found;
}
void lexer_open_stream(FILE *stream, const char *input_name)
{
- input = stream;
- source_position.linenr = 0;
- source_position.input_name = input_name;
+ input = stream;
+ lexer_token.source_position.linenr = 0;
+ lexer_token.source_position.input_name = input_name;
/* we place a virtual '\n' at the beginning so the lexer knows we're at the
* beginning of a line */
#include "symbol_table_t.h"
#include "token_t.h"
-void lexer_next_token(token_t *token);
+token_t lexer_token;
+
+void lexer_next_token(void);
/* for debugging */
-void lexer_next_preprocessing_token(token_t *token);
+void lexer_next_preprocessing_token(void);
+
+void init_lexer(void);
+void exit_lexer(void);
+
+void lexer_open_stream(FILE *stream, const char *input_name);
#endif
+++ /dev/null
-#ifndef LEXER_T_H
-#define LEXER_T_H
-
-#include "lexer.h"
-
-#include <stdio.h>
-#include "symbol_table_t.h"
-#include "adt/obst.h"
-#include "adt/strset.h"
-
-#define MAX_INDENT 256
-
-typedef struct source_position_t source_position_t;
-struct source_position_t {
- const char *input_name;
- unsigned linenr;
-};
-
-extern source_position_t source_position;
-
-void init_lexer(void);
-void exit_lexer(void);
-
-void lexer_open_stream(FILE *stream, const char *input_name);
-
-#endif
#include <errno.h>
#include <string.h>
-#include "lexer_t.h"
+#include "lexer.h"
#include "token_t.h"
#include "type_hash.h"
#include "parser.h"
lexer_open_stream(in, fname);
- token_t token;
do {
- lexer_next_preprocessing_token(&token);
- print_token(stdout, &token);
+ lexer_next_preprocessing_token();
+ print_token(stdout, &lexer_token);
puts("");
- } while(token.type != T_EOF);
+ } while(lexer_token.type != T_EOF);
fclose(in);
}
#include <stdarg.h>
#include "parser.h"
-#include "lexer_t.h"
+#include "lexer.h"
#include "token_t.h"
#include "type_t.h"
#include "type_hash.h"
#include "adt/array.h"
#define PRINT_TOKENS
+#define MAX_LOOKAHEAD 2
struct environment_entry_t {
- symbol_t *symbol;
- environment_entry_t *old_entry;
- declaration_t *declaration;
- unsigned short old_symbol_ID;
+ symbol_t *symbol;
+ declaration_t *old_declaration;
+ const void *old_context;
};
static token_t token;
+static token_t lookahead_buffer[MAX_LOOKAHEAD];
+static int lookahead_bufpos;
static struct obstack environment_obstack;
static environment_entry_t **environment_stack = NULL;
static translation_unit_t *translation_unit = NULL;
return res;
}
-/**
- * pushs an environment_entry on the environment stack and links the
- * corresponding symbol to the new entry
- */
-static inline
-environment_entry_t *environment_push(symbol_t *symbol)
-{
- environment_entry_t *entry
- = obstack_alloc(&environment_obstack, sizeof(entry[0]));
- memset(entry, 0, sizeof(entry[0]));
-
- int top = ARR_LEN(environment_stack);
- ARR_RESIZE(environment_stack, top + 1);
- environment_stack[top] = entry;
-
- entry->old_entry = symbol->thing;
- entry->symbol = symbol;
- symbol->thing = entry;
-
- return entry;
-}
-
-/**
- * pops symbols from the environment stack until @p new_top is the top element
- */
-static inline
-void environment_pop_to(size_t new_top)
-{
- environment_entry_t *entry = NULL;
- size_t top = ARR_LEN(environment_stack);
- size_t i;
-
- if(new_top == top)
- return;
-
- assert(new_top < top);
- i = top;
- do {
- entry = environment_stack[i - 1];
-
- symbol_t *symbol = entry->symbol;
-
-#if 0
- if(entry->type == ENTRY_LOCAL_VARIABLE
- && entry->e.variable->refs == 0) {
- variable_declaration_statement_t *variable = entry->e.variable;
- print_warning_prefix(env, variable->statement.source_position);
- fprintf(stderr, "variable '%s' was declared but never read\n",
- symbol->string);
- }
-#endif
-
- if(entry->declaration->storage_class == STORAGE_CLASS_TYPEDEF) {
- fprintf(stderr, "pop typename '%s'\n", entry->symbol->string);
- symbol->ID = entry->old_symbol_ID;
- }
-
- assert(symbol->thing == entry);
- symbol->thing = entry->old_entry;
-
- --i;
- } while(i != new_top);
- obstack_free(&environment_obstack, entry);
-
- ARR_SHRINKLEN(environment_stack, (int) new_top);
-}
-
/**
* returns the top element of the environment stack
*/
static inline
void next_token(void)
{
- lexer_next_token(&token);
+ token = lookahead_buffer[lookahead_bufpos];
+ lookahead_buffer[lookahead_bufpos] = lexer_token;
+ lexer_next_token();
+
+ lookahead_bufpos = (lookahead_bufpos+1) % MAX_LOOKAHEAD;
#ifdef PRINT_TOKENS
print_token(stderr, &token);
#endif
}
+static inline
+const token_t *la(int num)
+{
+ assert(num > 0 && num <= MAX_LOOKAHEAD);
+ int pos = (num-1) % MAX_LOOKAHEAD;
+ return & lookahead_buffer[pos];
+}
+
static inline
void eat(token_type_t type)
{
next_token();
}
-void parser_print_error_prefix(void)
+void parser_print_error_prefix_pos(const source_position_t source_position)
{
fputs(source_position.input_name, stderr);
fputc(':', stderr);
fputs(": error: ", stderr);
}
+void parser_print_error_prefix(void)
+{
+ parser_print_error_prefix_pos(token.source_position);
+}
+
static
void parse_error(const char *message)
{
} \
next_token();
+
+/**
+ * pushs an environment_entry on the environment stack and links the
+ * corresponding symbol to the new entry
+ */
+static inline
+void environment_push(declaration_t *declaration, const void *context)
+{
+ environment_entry_t *entry
+ = obstack_alloc(&environment_obstack, sizeof(entry[0]));
+ memset(entry, 0, sizeof(entry[0]));
+
+ int top = ARR_LEN(environment_stack);
+ ARR_RESIZE(environment_stack, top + 1);
+ environment_stack[top] = entry;
+
+ symbol_t *symbol = declaration->symbol;
+ assert(declaration != symbol->declaration);
+
+ if(symbol->context == context) {
+ if(context != NULL) {
+ assert(symbol->declaration != NULL);
+ parser_print_error_prefix_pos(declaration->source_position);
+ fprintf(stderr, "multiple definitions for symbol '%s'.\n",
+ symbol->string);
+ parser_print_error_prefix_pos(symbol->declaration->source_position);
+ fprintf(stderr, "this is the location of the previous declaration.\n");
+ }
+ }
+
+ entry->old_declaration = symbol->declaration;
+ entry->old_context = symbol->context;
+ entry->symbol = symbol;
+ symbol->declaration = declaration;
+ symbol->context = context;
+}
+
+/**
+ * pops symbols from the environment stack until @p new_top is the top element
+ */
+static inline
+void environment_pop_to(size_t new_top)
+{
+ environment_entry_t *entry = NULL;
+ size_t top = ARR_LEN(environment_stack);
+ size_t i;
+
+ if(new_top == top)
+ return;
+
+ assert(new_top < top);
+ i = top;
+ do {
+ entry = environment_stack[i - 1];
+
+ symbol_t *symbol = entry->symbol;
+
+ symbol->declaration = entry->old_declaration;
+ symbol->context = entry->old_context;
+
+ --i;
+ } while(i != new_top);
+ obstack_free(&environment_obstack, entry);
+
+ ARR_SHRINKLEN(environment_stack, (int) new_top);
+}
+
+
+
static expression_t *parse_constant_expression(void)
{
/* TODO: not correct yet */
compound_type_t *struct_type = allocate_type_zero(sizeof(struct_type[0]));
struct_type->type.type = TYPE_COMPOUND_STRUCT;
- struct_type->source_position = source_position;
+ struct_type->source_position = token.source_position;
- if(token.type == T_IDENTIFIER || token.type == T_TYPENAME) {
+ if(token.type == T_IDENTIFIER) {
/* TODO */
next_token();
if(token.type == '{') {
compound_type_t *union_type = allocate_type_zero(sizeof(union_type[0]));
union_type->type.type = TYPE_COMPOUND_UNION;
- union_type->source_position = source_position;
+ union_type->source_position = token.source_position;
if(token.type == T_IDENTIFIER) {
union_type->symbol = token.v.symbol;
enum_type_t *enum_type = allocate_type_zero(sizeof(enum_type[0]));
enum_type->type.type = TYPE_ENUM;
- enum_type->source_position = source_position;
+ enum_type->source_position = token.source_position;
if(token.type == T_IDENTIFIER) {
enum_type->symbol = token.v.symbol;
#endif
#define TYPE_SPECIFIERS \
- case T_TYPENAME: \
case T_void: \
case T_char: \
case T_short: \
case T_enum: \
COMPLEX_SPECIFIERS \
IMAGINARY_SPECIFIERS
+/* TODO: T_IDENTIFIER && typename */
#define DECLARATION_START \
STORAGE_CLASSES \
static
void parse_declaration_specifiers(declaration_specifiers_t *specifiers)
{
- type_t *type = NULL;
- unsigned type_qualifiers = 0;
- unsigned type_specifiers = 0;
+ declaration_t *declaration;
+ type_t *type = NULL;
+ unsigned type_qualifiers = 0;
+ unsigned type_specifiers = 0;
while(1) {
switch(token.type) {
}
break;
+ /* TODO: if type != NULL for the following rules issue an error */
case T_struct:
type = parse_struct_specifier();
break;
next_token();
break;
- case T_TYPENAME:
- if(type != NULL || type_specifiers != 0) {
+ case T_IDENTIFIER:
+ declaration = token.v.symbol->declaration;
+ if(declaration == NULL ||
+ declaration->storage_class != STORAGE_CLASS_TYPEDEF) {
goto finish_specifiers;
}
- type = token.v.symbol->thing->declaration->type;
+ type = declaration->type;
assert(type != NULL);
next_token();
break;
parse_declaration_specifiers(&specifiers);
specifiers.type = parse_pointer(specifiers.type);
- if(token.type == '(' || token.type == T_IDENTIFIER
- || token.type == T_TYPENAME) {
+ if(token.type == '(' || token.type == T_IDENTIFIER) {
declaration_t declaration;
memset(&declaration, 0, sizeof(declaration));
parse_declarator(&declaration, specifiers.storage_class,
declaration->type = type;
switch(token.type) {
- case T_TYPENAME:
case T_IDENTIFIER:
declaration->symbol = token.v.symbol;
next_token();
expect_void(')');
break;
default:
- parse_error_expected("problem while parsing declarator", T_TYPENAME,
- T_IDENTIFIER, '(', 0);
+ parse_error_expected("problem while parsing declarator", T_IDENTIFIER,
+ '(', 0);
}
while(1) {
symbol_t *symbol = declaration->symbol;
if(symbol != NULL) {
- environment_entry_t *entry = environment_push(symbol);
- entry->declaration = declaration;
- entry->old_symbol_ID = symbol->ID;
-
- if(storage_class == STORAGE_CLASS_TYPEDEF) {
- symbol->ID = T_TYPENAME;
- fprintf(stderr, "typedef '%s'\n", symbol->string);
- } else {
- symbol->ID = T_IDENTIFIER;
- }
+ environment_push(declaration, context);
}
}
expression_parser_function_t *parser
= &expression_parsers[token.type];
- source_position_t source_position = source_position;
+ source_position_t source_position = token.source_position;
expression_t *left;
if(parser->parser != NULL) {
statement_t *parse_label_statement(void)
{
eat(T_IDENTIFIER);
- expect(';');
+ expect(':');
parse_statement();
return NULL;
return NULL;
}
+static
+statement_t *parse_expression_statement(void)
+{
+ parse_expression();
+ return NULL;
+}
+
static
statement_t *parse_statement(void)
{
- statement_t *statement = NULL;
+ declaration_t *declaration;
+ statement_t *statement = NULL;
/* declaration or statement */
switch(token.type) {
statement = parse_default_statement();
break;
- case T_IDENTIFIER:
- statement = parse_label_statement();
- break;
-
case '{':
statement = parse_compound_statement();
break;
statement = NULL;
break;
+ case T_IDENTIFIER:
+ if(la(1)->type == ':') {
+ statement = parse_label_statement();
+ break;
+ }
+
+ declaration = token.v.symbol->declaration;
+ if(declaration != NULL &&
+ declaration->storage_class == STORAGE_CLASS_TYPEDEF) {
+ statement = parse_declaration_statement();
+ break;
+ }
+
+ statement = parse_expression_statement();
+ break;
+
DECLARATION_START
statement = parse_declaration_statement();
break;
obstack_init(&environment_obstack);
environment_stack = NEW_ARR_F(environment_entry_t*, 0);
- next_token();
+ lookahead_bufpos = 0;
+ for(int i = 0; i < MAX_LOOKAHEAD + 2; ++i) {
+ next_token();
+ }
translation_unit_t *unit = parse_translation_unit();
DEL_ARR_F(environment_stack);
#ifndef SYMBOL_H
#define SYMBOL_H
-#include "parser.h"
+#include "ast.h"
typedef struct symbol_t symbol_t;
struct symbol_t {
- const char *string;
- unsigned short ID;
- unsigned short pp_ID;
- environment_entry_t *thing;
+ const char *string;
+ unsigned short ID;
+ unsigned short pp_ID;
+ declaration_t *declaration;
+ const void *context;
};
#endif
static inline
void init_symbol_table_entry(symbol_t *entry, const char *string)
{
- entry->string = string;
- entry->ID = T_IDENTIFIER;
- entry->pp_ID = 0;
- entry->thing = NULL;
+ entry->string = string;
+ entry->ID = T_IDENTIFIER;
+ entry->pp_ID = 0;
+ entry->declaration = NULL;
+ entry->context = NULL;
}
#define HashSet symbol_table_t
case T_IDENTIFIER:
fprintf(f, "symbol '%s'", token->v.symbol->string);
break;
- case T_TYPENAME:
- fprintf(f, "typename '%s'", token->v.symbol->string);
- break;
case T_INTEGER:
fprintf(f, "integer number %d", token->v.intvalue);
break;
#undef T
} preprocessor_token_type_t;
+typedef struct source_position_t source_position_t;
+struct source_position_t {
+ const char *input_name;
+ unsigned linenr;
+};
+
typedef struct {
int type;
union {
int intvalue;
const char *string;
} v;
+ source_position_t source_position;
} token_t;
void init_tokens(void);
#endif
TS(IDENTIFIER, "identifier", = 256)
-TS(TYPENAME, "typename",)
TS(INTEGER, "integer number",)
TS(STRING_LITERAL, "string literal",)
#include "type.h"
#include "symbol.h"
-#include "lexer_t.h"
+#include "token_t.h"
#include "adt/obst.h"
struct obstack *type_obst;