F diff --git a/ast.c b/ast.c --- a/ast.c +++ b/ast.cret->type=ST_OBJECT_DECLARATION;ret->object=object;ret->scope=scope;+ ret->initializer=initializer;return ret;}ret=malloc(sizeof(struct AST_Translation_Unit));ret->type=TRANSLATION_UNIT;Queue_Init(&ret->components);- ret->scope=get_scope(parent_scope);+ /*TODO*/+ //ret->scope=get_scope(parent_scope);+ ret->scope=parent_scope;return ret;}F diff --git a/denoted.c b/denoted.c --- a/denoted.c +++ b/denoted.cret=malloc(sizeof(struct Denoted_Function));ret->denotation=DT_Function;ret->id=id;- ret->return_type=return_type;+ ret->type=return_type;ret->function_specifier=fs;ret->body=NULL;struct Denotation_Prototype *ret;ret=malloc(sizeof(struct Denotation_Prototype));ret->denotation=DT_Prototype;- ret->specifier=TS_NONE;+ ret->type=NULL;ret->storage_class=SC_NONE;+ ret->specifier=TS_NONE;ret->constraint=TC_NONE;ret->sign=TSIGN_NONE;ret->function_specifier=FS_None;+ ret->struct_union=NULL;+ ret->enumerator=NULL;ret->size=0;ret->is_const=ret->is_volatile=0;return get_denoted_error(get_denoted_function(NULL,((struct Type_Function*)base->type)->return_type,prototype->function_specifier));}else{- return get_denoted_function(base->id,((struct Type_Function*)base->type)->return_type,prototype->function_specifier);+ return get_denoted_function(base->id,base->type,prototype->function_specifier);}}else if(prototype->storage_class==SC_TYPEDEF){F diff --git a/denoted.h b/denoted.h --- a/denoted.h +++ b/denoted.hstruct Denoted_Base{enum Denotation_Type denotation;- struct Type *type;struct token *id;+ struct Type *type;};struct Denoted_Function{enum Denotation_Type denotation;- struct Type *return_type;struct token *id;+ struct Type *type;enum Function_Specifier function_specifier;struct Denoted_Typedef{enum Denotation_Type denotation;- struct Type *type;struct token *id;+ struct Type *type;};struct Denoted_EnumF diff --git a/lexer.c b/lexer.c --- a/lexer.c +++ b/lexer.cQueue_Init(tokens);while(src->src[src->where_in_src]!='\0'){- /*ignore leading spaces and tabs and check for double slash comment*/- while(src->src[src->where_in_src]==' ' || src->src[src->where_in_src]=='\n' || src->src[src->where_in_src]=='\t')- {- if(src->src[src->where_in_src]=='\n')- {- src->which_column=0;- ++src->which_row;- }else if(src->src[src->where_in_src]=='\t')- {- src->which_row+=5;- }- ++src->where_in_src;- }- if(src->src[src->where_in_src]=='\0')- break;if(src->which_column==0 && src->src[src->where_in_src]=='#'){}else{current_token=get_next_token(src,prog,&chonky[0]);- Queue_Push(tokens,current_token);+ if(current_token->type!=KW_NOTYPE)+ Queue_Push(tokens,current_token);+ else+ free(current_token);}}}}+ /*ignore leading spaces and tabs and check for double slash comment*/+ while(src->src[src->where_in_src]==' ' || src->src[src->where_in_src]=='\n' || src->src[src->where_in_src]=='\t')+ {+ if(src->src[src->where_in_src]=='\n')+ {+ src->which_column=0;+ ++src->which_row;+ }else if(src->src[src->where_in_src]=='\t')+ {+ src->which_row+=5;+ }+ ++src->where_in_src;+ }while(src->src[src->where_in_src]!='\0'){}ret=malloc(sizeof(struct token));ret->type=KW_NOTYPE;+ ret->data_size=0;+return ret;}#endifF diff --git a/main.exe b/main.exe deleted file mode 100755B Binary files a/main.exe and /dev/null differF diff --git a/parse_declaration.c b/parse_declaration.c --- a/parse_declaration.c +++ b/parse_declaration.cstruct Denoted *hold;prototype=parse_declaration_specifiers(tokens,scope);- while(!get_and_check(tokens,KW_SEMI_COLUMN))+ while(1){+ if(get_and_check(tokens,KW_SEMI_COLUMN))+ return;hold=parse_declarator(tokens,scope,prototype);if(hold->denotation==DT_Function && parse_function_definitions==1){if(get_and_check(tokens,KW_OPEN_CURLY)){((struct Denoted_Function*)hold)->body=(struct AST_Compound_Statement*)parse_finish_compound_statement(tokens,scope);- Queue_Push(where_to_push,get_function_declaration_tree(scope,(struct Denoted_Function*)hold));+ Queue_Push(where_to_push,get_function_definition_tree(scope,(struct Denoted_Function*)hold));Scope_Push(scope,hold);free(prototype);return;Scope_Push(scope,hold);parse_function_definitions=0;+ if(!get_and_check(tokens,KW_COMMA))+ {+ if(get_and_check(tokens,KW_SEMI_COLUMN))+ {+ return;+ }else+ {+ /*TODO error*/+ Queue_Push(where_to_push,get_declaration_error_tree(NULL));+ return;+ }+ }}free(prototype);if(tag==NULL){struct Struct_Union *body;- body=get_struct_union_base(ret->specifier);- parse_struct_union_specifier_finish(tokens,scope,body);+ body=get_struct_union_base(scope,ret->specifier);Scope_Push(scope,get_denoted_struct_union(id,body));++ parse_struct_union_specifier_finish(tokens,scope,body);ret->struct_union=body;}else{{return (struct Denotation_Prototype*)get_denoted_error((struct Denoted*)ret);}- if(ret->struct_union->members->size==0)+ if(ret->struct_union->is_finished==0){/*then this could be a definition*/- parse_struct_declaration(tokens,scope,ret->struct_union->members);+ parse_struct_union_specifier_finish(tokens,scope,ret->struct_union);}}}else{- ret->struct_union=get_struct_union_base(ret->specifier);+ ret->struct_union=get_struct_union_base(scope,ret->specifier);parse_struct_union_specifier_finish(tokens,scope,ret->struct_union);}break;{struct Enum *body;body=get_enum_base();- parse_enum_specifier_finish(tokens,scope,body);Scope_Push(scope,get_denoted_enum(id,body));+ parse_enum_specifier_finish(tokens,scope,body);ret->enumerator=body;}else{{return (struct Denotation_Prototype*)get_denoted_error((struct Denoted*)ret);}- if(ret->enumerator->consts->size==0)+ if(ret->enumerator->is_finished==0){/*this could be an enum definition*/parse_enum_specifier_finish(tokens,scope,ret->enumerator);{if(get_and_check(tokens,KW_OPEN_CURLY)){+ base->is_finished=1;while(parse_struct_declaration(tokens,base->inner_namespace,base->members)){struct Denotation_Prototype *prototype;struct Denoted *hold;prototype=parse_specifier_qualifier_list(tokens,struct_scope);- while(!get_and_check(tokens,KW_SEMI_COLUMN))+ while(1){hold=parse_struct_declarator(tokens,struct_scope,prototype);if(hold!=NULL && hold->denotation!=DT_Error)/*todo error*/return 0;}+ if(!get_and_check(tokens,KW_COMMA))+ {+ if(get_and_check(tokens,KW_SEMI_COLUMN))+ {+ break;+ }else+ {+ free(prototype);+ /*todo error*/+ return 0;+ }+ }}free(prototype);return 1;/*TODO error*/return get_denoted_error(hold);}+ }else+ {+ return hold;}}int where_in_enumeration=0;if(get_and_check(tokens,KW_OPEN_CURLY)){+ enumeration->is_finished=1;do{if(check(tokens,KW_ID,0))*/void parse_paramenter_list(struct Queue *tokens,struct Scope *function_prototype_scope,struct Queue *parameters){+ if(get_and_check(tokens,KW_CLOSE_NORMAL))+ return;+struct Denotation_Prototype *prototype;struct Denoted_Base temp;struct Denoted *hold;free(prototype);}while(get_and_check(tokens,KW_COMMA));+ if(!get_and_check(tokens,KW_CLOSE_NORMAL))+ {+ /*TODO error*/+ Queue_Push(parameters,get_denoted_error(NULL));+ return;+ }}/*{}++ const const const const const const const const const const const const const const const const const const const const const const const char const const const constant;#endifF diff --git a/parse_statement.c b/parse_statement.c --- a/parse_statement.c +++ b/parse_statement.chold=get_compound_statement_tree(scope);while(!get_and_check(tokens,KW_CLOSE_CURLY)){- if(is_type(tokens,scope))+ if(is_type(tokens,hold->scope)){parse_declaration(tokens,hold->scope,&hold->components,0);}elseF diff --git a/print.c b/print.c --- a/print.c +++ b/print.cif(unary_expression->type==OP_CAST){fprintf(out,"(");- print_type(out,unary_expression->value_type);+ print_type(out,unary_expression->value_type,1);fprintf(out,")");}print_ast(out,unary_expression->operand);print_token(out,got->label);}- void print_type(FILE *out,struct Type *type)+ void print_type(FILE *out,struct Type *type,char should_print_struct_union){switch(type->specifier){fprintf(out,"double");return;case TS_UNION:case TS_STRUCT:- print_struct_union(out,((struct Type_Struct_Union*)type)->struct_union);+ if(should_print_struct_union)+ {+ print_struct_union(out,((struct Type_Struct_Union*)type)->struct_union);+ }else+ {+ fprintf(out,(type->specifier==TS_STRUCT?"struct":"union"));+ }return;case TS_ENUM:print_enumeration(out,((struct Type_Enum*)type)->enumeration);return;case TS_POINTER:fprintf(out,"pointer to ");-- print_type(out,((struct Type_Pointer*)type)->points_to);+ print_type(out,((struct Type_Pointer*)type)->points_to,0);return;case TS_ARRAY:fprintf(out,"array [%zu] of ",((struct Type_Array*)type)->number_of_elements);- print_type(out,((struct Type_Array*)type)->is_array_of);+ print_type(out,((struct Type_Array*)type)->is_array_of,should_print_struct_union);return;case TS_FUNC:- fprintf(out,"a function taking arguments ");+ fprintf(out,"function taking arguments (");print_list_of_denoted(out,((struct Type_Function*)type)->parameters);- fprintf(out,"returning ");- print_type(out,((struct Type_Function*)type)->return_type);+ fprintf(out,") returning ");+ print_type(out,((struct Type_Function*)type)->return_type,should_print_struct_union);return;case TS_BITFIELD:fprintf(out,"%zu bits of ",((struct Type_Bit_Field*)type)->number_of_bits);- print_type(out,((struct Type_Bit_Field*)type)->base);+ print_type(out,((struct Type_Bit_Field*)type)->base,should_print_struct_union);return;case TS_NONE:fprintf(out,"NONE");return;case DT_Label:fprintf(out,"label ");return;case DT_Object:- fprintf(out,"object");return;+ fprintf(out,"denoted object ");+ print_token(out,((struct Denoted_Object*)denoted)->id);+ fprintf(out," is a ");+ print_type(out,((struct Denoted_Object*)denoted)->object->type,1);++ return;case DT_Typedef:fprintf(out,"typedef ");print_token(out,((struct Denoted_Typedef*)denoted)->id);- fprintf(out,"to ");- print_type(out,((struct Denoted_Typedef*)denoted)->type);+ fprintf(out," to ");+ print_type(out,((struct Denoted_Typedef*)denoted)->type,0);return;case DT_Function:print_token(out,((struct Denoted_Function*)denoted)->id);- fprintf(out,"is a");- print_type(out,((struct Denoted_Function*)denoted)->return_type);+ fprintf(out," is ");+ print_type(out,((struct Denoted_Function*)denoted)->type,1);return;case DT_Enum:print_token(out,((struct Denoted_Enum*)denoted)->id);- fprintf(out,"is a");+ fprintf(out," is ");print_enumeration(out,((struct Denoted_Enum*)denoted)->enumeration);return;case DT_Enum_Constant:return;case DT_Struct_Union_Tag:print_token(out,((struct Denoted_Struct_Union*)denoted)->id);- fprintf(out,"is a");+ fprintf(out," is ");print_struct_union(out,((struct Denoted_Struct_Union*)denoted)->struct_union);case DT_Error:fprintf(out,"denotation error");return;default:assert(1==0);}+ fprintf(out,"{");print_list_of_denoted(out,struct_union->members);+ fprintf(out,"}");}void print_translation_unit_tree(FILE *out,struct AST_Translation_Unit *unit)}void print_ast(FILE *out,struct AST* tree){+ if(tree==NULL)+ {+ fprintf(out,"NULL");+ return ;+ }switch(tree->type){case OP_MEMBER_TROUGH_PTR:fprintf(out,"=");print_ast(out,((struct AST_Object_Declaration*)tree)->initializer);break;+ case ST_TYPE_DEFINITION:+ print_denoted(out,(struct Denoted*)((struct AST_Type_Definition*)tree)->definition);+ break;case ST_FUNCTION_DECLARATION:print_denoted(out,(struct Denoted*)((struct AST_Function_Declaration*)tree)->function);break;void print_function_definition(FILE *out,struct Denoted_Function *function){print_token(out,function->id);- fprintf(out,"is a ");- print_type(out,function->return_type);+ fprintf(out," is a ");+ print_type(out,function->type,1);print_ast(out,(struct AST*)function->body);}void print_program_tokens(FILE *out,struct Program *program)F diff --git a/print.h b/print.h --- a/print.h +++ b/print.hvoid print_for_statement_tree(FILE *out,struct AST_For_Statement *fo);void print_return_statement_tree(FILE *out,struct AST_Return_Statement *return_expression);void print_goto_statement_tree(FILE *out,struct AST_Goto_Statement *got);- void print_type(FILE *out,struct Type *type);+ void print_type(FILE *out,struct Type *type,char print_struct_union);void print_denoted(FILE *out,struct Denoted *denoted);void print_list_of_denoted(FILE *out,struct Queue *denoted);void print_enumeration(FILE *out,struct Enum *enumeration);F diff --git a/scope.c b/scope.c --- a/scope.c +++ b/scope.creturn hold;}- char Scope_Push(struct Scope *scope,struct Denoted *declarator)+ void Scope_Push(struct Scope *scope,struct Denoted *declarator){- return 0;+ switch(declarator->denotation)+ {+ /*+ case DT_Label:+ if(check_label(scope,((struct Denoted_Object+ return 1;+ */+ case DT_Function:+ case DT_Typedef:+ case DT_Object:+ case DT_Enum_Constant:+ case DT_Struct_Union_Member:+ push_ordinary(scope,((struct Denoted_Object*)declarator)->id,declarator);+ return;+ case DT_Enum:+ case DT_Struct_Union_Tag:+ push_tag(scope,((struct Denoted_Object*)declarator)->id,declarator);+ return;+ }}char check_if_typedefed(struct Scope* scope,struct token *id){+ struct Denoted *hold;+ hold=check_ordinary(scope,id);+ if(hold==NULL || hold->denotation!=DT_Typedef)+ return 0;+ else+ return 1;++ }+ void push_tag(struct Scope *current,struct token *id,struct Denoted *denot)+ {+ Map_Push(¤t->tags,id->data,id->data_size,denot);+ }+ void push_ordinary(struct Scope *current,struct token *id,struct Denoted *denot)+ {+ Map_Push(¤t->ordinary,id->data,id->data_size,denot);}#endifF diff --git a/scope.h b/scope.h --- a/scope.h +++ b/scope.hstruct Scope* get_scope(struct Scope *parent);+void* check_label(struct Scope *current,struct token *id);++ void push_label(struct Scope *current,struct token *id);/*TODO*/+struct Denoted* check_tag(struct Scope *current,struct token *id);+ void push_tag(struct Scope *current,struct token *id,struct Denoted *denot);+void* check_ordinary(struct Scope *current,struct token *id);- char Scope_Push(struct Scope *scope,struct Denoted* denoted);+ void push_ordinary(struct Scope *current,struct token *id,struct Denoted *denot);++ void Scope_Push(struct Scope *scope,struct Denoted *declarator);char check_if_typedefed(struct Scope* scope,struct token *id);#endifF diff --git a/test.c b/test.c --- a/test.c +++ b/test.c- #/*asdf*/include/*asd*/<tes\- t2.c>+ #include "test2.c"+ List ints;int main(){- struct ke asdf;+ long int c;+ int a,b;++ c=a+b;return 0;}F diff --git a/test2.c b/test2.c --- a/test2.c +++ b/test2.c{int s;};+ typedef int List;F diff --git a/type.c b/type.c --- a/type.c +++ b/type.cret->is_const=prototype->is_const;ret->is_volatile=prototype->is_volatile;- if(prototype->constraint!=TC_NONE || prototype->size!=TSIGN_NONE || (prototype->specifier!=TS_ENUM && prototype->specifier!=TS_STRUCT))+ if(prototype->constraint!=TC_NONE || prototype->sign!=TSIGN_NONE || (prototype->specifier!=TS_UNION && prototype->specifier!=TS_STRUCT)){return (struct Type*)get_type_error((struct Type*)ret);}elsereturn (struct Type*)ret;}}- struct Struct_Union* get_struct_union_base(enum Type_Specifier struct_or_union)+ struct Struct_Union* get_struct_union_base(struct Scope *scope ,enum Type_Specifier struct_or_union){struct Struct_Union *ret;ret=malloc(sizeof(struct Struct_Union));ret->members=malloc(sizeof(struct Queue));Queue_Init(ret->members);- ret->inner_namespace=get_scope(NULL);+ ret->inner_namespace=get_scope(scope);+ ret->is_finished=0;return ret;}ret->consts=malloc(sizeof(struct Queue));Queue_Init(ret->consts);+ ret->is_finished=0;+return ret;}/*could return error*/return (struct Type*)get_type_error((struct Type*)ret);}break;+ case TS_INT:+ break;default:if(prototype->constraint!=TC_NONE || prototype->sign!=TSIGN_NONE){{case KW_ID:thing=check_ordinary(scope,hold);- if(thing->denotation==DT_Typedef)+ if(thing!=NULL && thing->denotation==DT_Typedef)return 1;else return 0;case KW_CONST:F diff --git a/type.h b/type.h --- a/type.h +++ b/type.h+ //typedef void ;struct Denotation_Prototype;/*this isn't just type-specifier*/size_t size;struct Queue *members;struct Scope *inner_namespace;++ char is_finished;};struct Type_Bit_Field{{enum Type_Specifier specifier;struct Queue *consts;+ char is_finished;};struct Type* get_type_error(struct Type* error);struct Type* get_struct_union_type(struct Denotation_Prototype *prototype);- struct Struct_Union* get_struct_union_base(enum Type_Specifier struct_or_union);+ struct Struct_Union* get_struct_union_base(struct Scope *scope ,enum Type_Specifier struct_or_union);struct Enum *get_enum_base();struct Type* get_basic_type(struct Denotation_Prototype *prototype);struct Type* get_pointer_type(struct Type* points_to);