F diff --git a/src/backend/text/print/print.c b/src/backend/text/print/print.c
--- a/src/backend/text/print/print.c
+++ b/src/backend/text/print/print.c
void print_token(struct Compile_Data_Print *compile_data,struct token *token)
{
- char *token_string;
- wonky_assert(SHOULD_NOT_REACH_HERE);
- //token_string=gstr_dup(token->data,token->data+token->data_size,1024);
- //append_to_last_line(token_string,compile_data->lines);
+ push_line(gstr_to_heap("[ "),compile_data->indent,compile_data->lines);
+ switch(token->type)
+ {
+ case KW_AUTO:
+ append_to_last_line("AUTO",compile_data->lines);
+ break;
+ case KW_DO:
+ append_to_last_line("DO",compile_data->lines);
+ break;
+ case KW_DOUBLE:
+ append_to_last_line("DOUBLE",compile_data->lines);
+ break;
+ case KW_INT:
+ append_to_last_line("INT",compile_data->lines);
+ break;
+ case KW_STRUCT:
+ append_to_last_line("STRUCT",compile_data->lines);
+ break;
+ case KW_BREAK:
+ append_to_last_line("BREAK",compile_data->lines);
+ break;
+ case KW_ELSE:
+ append_to_last_line("ELSE",compile_data->lines);
+ break;
+ case KW_LONG:
+ append_to_last_line("LONG",compile_data->lines);
+ break;
+ case KW_SWITCH:
+ append_to_last_line("SWITCH",compile_data->lines);
+ break;
+ case KW_CASE:
+ append_to_last_line("CASE",compile_data->lines);
+ break;
+ case KW_ENUM:
+ append_to_last_line("ENUM",compile_data->lines);
+ break;
+ case KW_REGISTER:
+ append_to_last_line("REGISTER",compile_data->lines);
+ break;
+ case KW_TYPEDEF:
+ append_to_last_line("TYPEDEF",compile_data->lines);
+ break;
+ case KW_CHAR:
+ append_to_last_line("CHAR",compile_data->lines);
+ break;
+ case KW_EXTERN:
+ append_to_last_line("EXTERN",compile_data->lines);
+ break;
+ case KW_RETURN:
+ append_to_last_line("RETURN",compile_data->lines);
+ break;
+ case KW_UNION:
+ append_to_last_line("UNION",compile_data->lines);
+ break;
+ case KW_CONST:
+ append_to_last_line("CONST",compile_data->lines);
+ break;
+ case KW_FLOAT:
+ append_to_last_line("FLOAT",compile_data->lines);
+ break;
+ case KW_SHORT:
+ append_to_last_line("SHORT",compile_data->lines);
+ break;
+ case KW_UNSIGNED:
+ append_to_last_line("UNSIGNED",compile_data->lines);
+ break;
+ case KW_CONTINUE:
+ append_to_last_line("CONTINUE",compile_data->lines);
+ break;
+ case KW_FOR:
+ append_to_last_line("FOR",compile_data->lines);
+ break;
+ case KW_SIGNED:
+ append_to_last_line("SIGNED",compile_data->lines);
+ break;
+ case KW_VOID:
+ append_to_last_line("VOID",compile_data->lines);
+ break;
+ case KW_DEFAULT:
+ append_to_last_line("DEFAULT",compile_data->lines);
+ break;
+ case KW_GOTO:
+ append_to_last_line("GOTO",compile_data->lines);
+ break;
+ case KW_SIZEOF:
+ append_to_last_line("SIZEOF",compile_data->lines);
+ break;
+ case KW_VOLATILE:
+ append_to_last_line("VOLATILE",compile_data->lines);
+ break;
+ case KW_IF:
+ append_to_last_line("IF",compile_data->lines);
+ break;
+ case KW_STATIC:
+ append_to_last_line("STATIC",compile_data->lines);
+ break;
+ case KW_WHILE:
+ append_to_last_line("WHILE",compile_data->lines);
+ break;
+ case KW_EXCLAMATION:
+ append_to_last_line("!",compile_data->lines);
+ break;
+ case KW_PERCENT:
+ append_to_last_line("%",compile_data->lines);
+ break;
+ case KW_AND:
+ append_to_last_line("&",compile_data->lines);
+ break;
+ case KW_AND_AND:
+ append_to_last_line("&&",compile_data->lines);
+ break;
+ case KW_OPEN_NORMAL:
+ append_to_last_line("(",compile_data->lines);
+ break;
+ case KW_CLOSE_NORMAL:
+ append_to_last_line(")",compile_data->lines);
+ break;
+ case KW_STAR:
+ append_to_last_line("*",compile_data->lines);
+ break;
+ case KW_PLUS:
+ append_to_last_line("+",compile_data->lines);
+ break;
+ case KW_COMMA:
+ append_to_last_line(",",compile_data->lines);
+ break;
+ case KW_MINUS:
+ append_to_last_line("-",compile_data->lines);
+ break;
+ case KW_DOT:
+ append_to_last_line(".",compile_data->lines);
+ break;
+ case KW_ARROW:
+ append_to_last_line("->",compile_data->lines);
+ break;
+ case KW_COLUMN:
+ append_to_last_line(":",compile_data->lines);
+ break;
+ case KW_SEMI_COLUMN:
+ append_to_last_line(";",compile_data->lines);
+ break;
+ case KW_LESS:
+ append_to_last_line("<",compile_data->lines);
+ break;
+ case KW_EQ:
+ append_to_last_line("=",compile_data->lines);
+ break;
+ case KW_EQEQ:
+ append_to_last_line("==",compile_data->lines);
+ break;
+ case KW_MORE:
+ append_to_last_line(">",compile_data->lines);
+ break;
+ case KW_QUESTION:
+ append_to_last_line("?",compile_data->lines);
+ break;
+ case KW_HAT:
+ append_to_last_line("^",compile_data->lines);
+ break;
+ case KW_PIPE:
+ append_to_last_line("|",compile_data->lines);
+ break;
+ case KW_PIPE_PIPE:
+ append_to_last_line("||",compile_data->lines);
+ break;
+ case KW_TILDE:
+ append_to_last_line("~",compile_data->lines);
+ break;
+ case KW_PLUSPLUS:
+ append_to_last_line("++",compile_data->lines);
+ break;
+ case KW_MINUSMINUS:
+ append_to_last_line("--",compile_data->lines);
+ break;
+ case KW_SHIFT_RIGHT:
+ append_to_last_line(">>",compile_data->lines);
+ break;
+ case KW_SHIFT_LEFT:
+ append_to_last_line("<<",compile_data->lines);
+ break;
+ case KW_LESS_EQ:
+ append_to_last_line("<=",compile_data->lines);
+ break;
+ case KW_MORE_EQ:
+ append_to_last_line(">=",compile_data->lines);
+ break;
+ case KW_NOT_EQ:
+ append_to_last_line("!=",compile_data->lines);
+ break;
+ case KW_PLUS_EQ:
+ append_to_last_line("+=",compile_data->lines);
+ break;
+ case KW_MINUS_EQ:
+ append_to_last_line("-=",compile_data->lines);
+ break;
+ case KW_STAR_EQ:
+ append_to_last_line("*=",compile_data->lines);
+ break;
+ case KW_PERCENT_EQ:
+ append_to_last_line("%=",compile_data->lines);
+ break;
+ case KW_SHIFT_LEFT_EQ:
+ append_to_last_line("<<=",compile_data->lines);
+ break;
+ case KW_SHIFT_RIGHT_EQ:
+ append_to_last_line(">>=",compile_data->lines);
+ break;
+ case KW_AND_EQ:
+ append_to_last_line("&=",compile_data->lines);
+ break;
+ case KW_HAT_EQ:
+ append_to_last_line("^=",compile_data->lines);
+ break;
+ case KW_PIPE_EQ:
+ append_to_last_line("|=",compile_data->lines);
+ break;
+ case KW_HASHTAG:
+ append_to_last_line("#",compile_data->lines);
+ break;
+ case KW_HASHTAG_HASHTAG:
+ append_to_last_line("##",compile_data->lines);
+ break;
+ case KW_ELIPSIS:
+ append_to_last_line("...",compile_data->lines);
+ break;
+ case KW_DIV:
+ append_to_last_line("/",compile_data->lines);
+ break;
+ case KW_INLINE:
+ append_to_last_line("INLINE",compile_data->lines);
+ break;
+ case KW_RESTRICT:
+ append_to_last_line("RESTRICT",compile_data->lines);
+ break;
+ case KW_BOOL:
+ append_to_last_line("_BOOL",compile_data->lines);
+ break;
+ case KW_COMPLEX:
+ append_to_last_line("_COMPLEX",compile_data->lines);
+ break;
+ case KW_IMAGINARY:
+ append_to_last_line("_IMAGINARY",compile_data->lines);
+ break;
+ case KW_OPEN_SQUARE:
+ append_to_last_line("[",compile_data->lines);
+ break;
+ case KW_CLOSE_SQUARE:
+ append_to_last_line("]",compile_data->lines);
+ break;
+ case KW_CLOSE_CURLY:
+ append_to_last_line("}",compile_data->lines);
+ break;
+ case KW_OPEN_CURLY:
+ append_to_last_line("{",compile_data->lines);
+ break;
+ case KW_DIV_EQ:
+ append_to_last_line("/=",compile_data->lines);
+ break;
+ case KW_FORWARD_SLASH:
+ append_to_last_line("/",compile_data->lines);
+ break;
+ case KW_NOTYPE:
+ append_to_last_line("NOTYPE",compile_data->lines);
+ break;
+ case KW_HEXADECIMAL_CONSTANT:
+ case KW_DECIMAL_CONSTANT:
+ case KW_OCTAL_CONSTANT :
+ case KW_UNSIGNED_DECIMAL_CONSTANT:
+ case KW_UNSIGNED_OCTAL_CONSTANT:
+ case KW_UNSIGNED_HEXADECIMAL_CONSTANT:
+ case KW_UNSIGNED_LONG_HEXADECIMAL_CONSTANT:
+ case KW_UNSIGNED_LONG_OCTAL_CONSTANT:
+ case KW_UNSIGNED_LONG_DECIMAL_CONSTANT:
+ case KW_UNSIGNED_LONG_LONG_DECIMAL_CONSTANT:
+ case KW_UNSIGNED_LONG_LONG_HEXADECIMAL_CONSTANT:
+ case KW_UNSIGNED_LONG_LONG_OCTAL_CONSTANT:
+ case KW_LONG_HEXADECIMAL_CONSTANT:
+ case KW_LONG_OCTAL_CONSTANT:
+ case KW_LONG_DECIMAL_CONSTANT:
+ case KW_LONG_LONG_HEXADECIMAL_CONSTANT:
+ case KW_LONG_LONG_OCTAL_CONSTANT:
+ case KW_LONG_LONG_DECIMAL_CONSTANT:
+ case KW_DOUBLE_DECIMAL_CONSTANT:
+ case KW_LONG_DOUBLE_DECIMAL_CONSTANT:
+ case KW_FLOAT_DECIMAL_CONSTANT:
+ case KW_DOUBLE_HEXADECIMAL_CONSTANT:
+ case KW_LONG_DOUBLE_HEXADECIMAL_CONSTANT:
+ case KW_FLOAT_HEXADECIMAL_CONSTANT:
+ case KW_CHAR_CONSTANT:
+ case KW_WIDE_CHAR_CONSTANT:
+ case KW_CONSTANT:
+ append_to_last_line("CONSTANT",compile_data->lines);
+ break;
+ case KW_ID:
+ append_to_last_line("ID",compile_data->lines);
+ break;
+ case KW_STRING:
+ case KW_WIDE_STRING:
+ append_to_last_line("STRING",compile_data->lines);
+ break;
+
+ default:
+ append_to_last_line("NOTYPE",compile_data->lines);
+
+ }
+ append_to_last_line(" ]",compile_data->lines);
}
char print_tokens_of_program(FILE *out,char **base_source_names)
struct Source_File *src;
struct Program *program;
+ struct Token_Pointer *ptr;
+ struct Compile_Data_Print *data;
+ struct Compiled_Object_Print *obj;
+ struct Preprocessing_Translation_Unit *hold_unit;
+
char *this_directory[]={"./",NULL};
_Bool ret;
ret=0;
program=get_program();
+ data=get_print_compile_data();
do
{
src=get_source_file_from_string(*base_source_names,gstrnlen(*base_source_names,1000));
- lex(src,program);
+ hold_unit=lex(src,program);
if(program->errors->size>0)
{
ret=1;
}
fprintf(out,"\nTOKENS OF %s {\n",src->src_name->full_name);
- print_tokens(out,((struct Preprocessing_Translation_Unit*)program->preprocessing_translation_units_to_be_compiled->first)->tokens);
+
+ ptr=get_token_ptr(hold_unit);
+ print_tokens(out,ptr,data);
+
+ obj=get_print_compile_object(data->lines);
+ save_compiled_object_for_print(obj,out);
+
fprintf(out,"\n} END OF TOKENS\n");
}while(*(++base_source_names));
return ret;
}
- void print_tokens(FILE *out,struct Queue *tokens)
+ void print_tokens(FILE *out,struct Token_Pointer *ptr,struct Compile_Data_Print *data)
{
- struct Queue_Node *it;
- size_t i;
- struct token *token;
- for( it=tokens->first; it!=NULL; it=it->prev)
+ while(token_ptr_has_remaining_tokens(ptr))
{
- token=it->data;
- fprintf(out,"[");
- print_keyword_enum(out,token->type);
-
- /*
- if(token->data==NULL)continue;
- for(i=0;i<token->data_size;++i)
- {
- fprintf(out,"%c",token->data[i]);
- }
- */
-
- fprintf(out,"] ");
+ print_token(data,token_ptr_get_token_under_pointer(ptr));
}
}
F diff --git a/src/backend/text/print/print.h b/src/backend/text/print/print.h
--- a/src/backend/text/print/print.h
+++ b/src/backend/text/print/print.h
struct Queue *lines;
-
-
};
struct Compiled_Object_Print* compile_program_for_print(struct Program *program);
void print_token(struct Compile_Data_Print *compile_data,struct token *token);
- void print_tokens(FILE *out,struct Queue *tokens);
+ void print_tokens(FILE *out,struct Token_Pointer *ptr,struct Compile_Data_Print *data);
char print_tokens_of_program(FILE *out,char **base_source_names);
void print_ast_enum(struct Compile_Data_Print *compile_data,enum AST_Type op);
void print_error_tree(struct Compile_Data_Print *compile_data,struct AST_Error *error);
F diff --git a/src/frontend/lex/lexer.c b/src/frontend/lex/lexer.c
--- a/src/frontend/lex/lexer.c
+++ b/src/frontend/lex/lexer.c
/*asdf*/#include <lexer.h>
- void lex(struct Source_File *src,struct Program *program)
+ struct Preprocessing_Translation_Unit* lex(struct Source_File *src,struct Program *program)
{
struct Lexer_Data *lexer_data;
struct Preprocessing_Translation_Unit *lexed_unit;
delete_lexer_data(lexer_data);
+ return lexed_unit;
}
struct Preprocessing_Translation_Unit *unit;
struct token *token;
+ unit=get_preprocessing_translation_unit(lexer_data->src);
+
while(!lexer_eof(lexer_data))
{
token=lexer_extract_next_token(lexer_data);
- push_token_into_preprocessing_translation_unit(unit,token);
+ if(token!=NULL)
+ push_token_into_preprocessing_translation_unit(unit,token);
}
return unit;
where_does_the_token_start_in_the_source_file=lexer_data->where_in_src;
hold_node=lexer_feed_automata_until_error(lexer_data);
+
+ if(lexer_eof(lexer_data))
+ return NULL;
+
if(hold_node==NULL)
- if(lexer_eof(lexer_data))
- return get_eof_token();
- else
- return get_error_token("Unrecognised lexical element",get_source_location(
- lexer_data->which_column,
- lexer_data->which_row,
- lexer_data->where_in_src,
- lexer_data->src->src_name
- ),
+ return get_error_token("Unrecognised lexical element",get_source_location(
+ lexer_data->which_column,
+ lexer_data->which_row,
+ lexer_data->where_in_src,
+ lexer_data->src->src_name
+ ),
lexer_data->program);
- }while(hold_node->keyword!=KW_COMMENT);
+ }while(hold_node->keyword==KW_COMMENT);
ret=lexer_make_token_finishing_on_node(lexer_data, hold_node, where_does_the_token_start_in_the_source_file);
lexer_data->is_in_the_begining_of_line=0;
size_t hold_which_column;
size_t hold_which_row;
struct Automata_Node *ret;
+ enum Source_Chars ch;
state=UNKNOWN_CHAR;
hold_where_in_src=lexer_data->where_in_src;
}while(state!=KNOWN_CHAR);
- ret=node->delta[get_ch(& lexer_data->src->src[lexer_data->where_in_src],1)];
+ ch=get_ch(& lexer_data->src->src[lexer_data->where_in_src],1);
+ ret=node->delta[ch];
if(ret==NULL)
{
lexer_data->where_in_src=hold_where_in_src;
return NULL;
}else
{
+ switch(ch)
+ {
+ case CHAR_VERTICAL_TAB:
+ case CHAR_FORM_FEED_TAB:
+ ++lexer_data->which_row;
+ ++lexer_data->where_in_src;
+ lexer_data->which_column=0;
+ break;
+ default:
+ ++lexer_data->which_column;
+ ++lexer_data->where_in_src;
+ }
return ret;
}
}
F diff --git a/src/frontend/lex/lexer.h b/src/frontend/lex/lexer.h
--- a/src/frontend/lex/lexer.h
+++ b/src/frontend/lex/lexer.h
- void lex(struct Source_File *src,struct Program *program);
+ struct Preprocessing_Translation_Unit* lex(struct Source_File *src,struct Program *program);
struct Preprocessing_Translation_Unit* lex_inner(struct Lexer_Data *lexer_data);
struct Lexer_Data* get_lexer_data(struct Source_File *src,struct Program *program);
F diff --git a/src/frontend/parse/parse_statement.c b/src/frontend/parse/parse_statement.c
--- a/src/frontend/parse/parse_statement.c
+++ b/src/frontend/parse/parse_statement.c
void chase_next_semicolumn(struct Translation_Data *translation_data)
{
/*chase ; and start parsing next declaration*/
- while(!get_and_check(translation_data,KW_SEMI_COLUMN) && !check(translation_data,KW_CLOSE_CURLY) &&
+ while(!get_and_check(translation_data,KW_SEMI_COLUMN) && !get_and_check(translation_data,KW_CLOSE_CURLY) &&
!translation_eof(translation_data))
{
chomp(translation_data);
F diff --git a/src/semantics/program/program.c b/src/semantics/program/program.c
--- a/src/semantics/program/program.c
+++ b/src/semantics/program/program.c
ret->source_files=wonky_malloc(sizeof(struct Queue));
ret->errors=wonky_malloc(sizeof(struct Queue));
ret->types=wonky_malloc(sizeof(struct Map));
+
+ ret->preprocessing_translation_units=wonky_malloc(sizeof(struct Map));
+ ret->preprocessing_translation_units_to_be_compiled=wonky_malloc(sizeof(struct Queue));
+
ret->functions_without_a_definition=wonky_malloc(sizeof(struct Queue));
ret->external_objects_without_an_initialiser=wonky_malloc(sizeof(struct Queue));
+
ret->external_linkage=get_linkage();
Queue_Init(ret->translation_units);
Queue_Init(ret->source_files);
Queue_Init(ret->errors);
+ Queue_Init(ret->preprocessing_translation_units_to_be_compiled);
Queue_Init(ret->functions_without_a_definition);
Queue_Init(ret->external_objects_without_an_initialiser);
Map_Init(ret->types);
+ Map_Init(ret->preprocessing_translation_units);
return ret;
}
do
{
base_file=get_source_file_from_string(*base_source_names,gstrnlen(*base_source_names,1000));
- lex(base_file,program);
+ Queue_Push(program->preprocessing_translation_units_to_be_compiled,lex(base_file,program));
}while(*(++base_source_names) != NULL);
if(program_has_errors(program))
enum LEXER_TYPE kw_get(struct Translation_Data *translation_data)
{
struct token *hold_token;
- if(token_ptr_has_remaining_tokens(translation_data->token_pointer))
+ if(!token_ptr_has_remaining_tokens(translation_data->token_pointer))
{
- return 0;
+ return LT_ERROR;
}else
{
hold_token=token_ptr_check_next_normal_token(translation_data->token_pointer);
}
_Bool translation_eof(struct Translation_Data *translation_data)
{
- return token_ptr_has_remaining_tokens(translation_data->token_pointer);
+ return !token_ptr_has_remaining_tokens(translation_data->token_pointer);
}
#endif
F diff --git a/src/semantics/program/translation_unit.c b/src/semantics/program/translation_unit.c
--- a/src/semantics/program/translation_unit.c
+++ b/src/semantics/program/translation_unit.c
token_ptr_goto_next_token(token_pointer);
+ token_ptr_assume_location_of_token(token_pointer,hold_token);
return hold_token;
-
-
}
void token_ptr_goto_next_normal_token(struct Token_Pointer *token_pointer)
{
struct token *hold_token;
+ if(token_pointer->current_token_node==NULL)
+ return;
while(1)
{
hold_token=(struct token*)token_pointer->current_token_node->data;
+ if(hold_token==NULL)
+ return;
+
switch(hold_token->type)
{
case PKW_IF:
}
struct token* token_ptr_check_next_normal_token(struct Token_Pointer *token_pointer)
{
- token_ptr_goto_next_normal_token(token_pointer);
+ struct token *ret;
if(token_pointer->current_token_node==NULL)
return get_eof_token();
else
}
void token_ptr_goto_next_token(struct Token_Pointer *token_pointer)
{
- wonky_assert(token_pointer!=NULL);
- wonky_assert(token_pointer->current_token_node!=NULL);
-
- if(token_pointer->current_token_node->next!=NULL && ((struct token*)token_pointer->current_token_node->data)->type!=LT_EOF)
- {
- token_pointer->current_token_node=token_pointer->current_token_node->next;
- }
+ if(token_pointer->current_token_node!=NULL)
+ token_pointer->current_token_node=token_pointer->current_token_node->prev;
}
struct Token_Pointer* get_token_ptr(struct Preprocessing_Translation_Unit *unit)
{
Queue_Push(ptr->ungeted_tokens,token);
}
+ void token_ptr_assume_location_of_token(struct Token_Pointer *ptr,struct token *token)
+ {
+ ptr->current_location=token->location;
+ }
#endif
F diff --git a/src/semantics/program/translation_unit.h b/src/semantics/program/translation_unit.h
--- a/src/semantics/program/translation_unit.h
+++ b/src/semantics/program/translation_unit.h
void token_ptr_execute_pragma_directive(struct Token_Pointer *ptr,struct token_pragma_directive *pragma_directive);
void token_ptr_execute_defined_unary_operator(struct Token_Pointer *ptr,struct token_defined_unary_operator *operator);
+ void token_ptr_assume_location_of_token(struct Token_Pointer *ptr,struct token *token);
+
#endif
F diff --git a/src/syntax/source_file.c b/src/syntax/source_file.c
--- a/src/syntax/source_file.c
+++ b/src/syntax/source_file.c
}
struct Source_Name* get_source_name_from_string(char *filename,size_t filename_size)
{
- size_t which_base;
- which_base=0;
+ struct Source_Name *ret;
+
+ ret=wonky_malloc(sizeof(struct Source_Name));
+ ret->filename=ret->base=ret->full_name=filename;
+ ret->filename_size=ret->base_size=ret->full_name_size=filename_size;
+ return ret;
}
struct Source_Name* get_source_name_from_string_inner(char *filename,size_t filename_size)
{
F diff --git a/src/syntax/token/token.h b/src/syntax/token/token.h
--- a/src/syntax/token/token.h
+++ b/src/syntax/token/token.h
struct token
{
enum LEXER_TYPE type;
+ struct Source_Location *location;
};
struct token_identifier
{