F diff --git a/src/frontend/parse/parse_declaration.c b/src/frontend/parse/parse_declaration.c
--- a/src/frontend/parse/parse_declaration.c
+++ b/src/frontend/parse/parse_declaration.c
function_type->function_prototype_scope->parent=(struct Scope*)hold_function->function_scope;
hold_function->body=
- (struct AST_Compound_Statement*)parse_finish_compound_statement(translation_data,(struct Scope*)function_type->function_prototype_scope);
+ (struct AST_Compound_Statement*)parse_finish_compound_statement(translation_data,(struct Scope*)function_type->function_prototype_scope,NULL,NULL);
Queue_Push(where_to_push,get_function_definition_tree(scope,(struct Denoted_Function*)hold));
break;
}
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
#include "parse_statement.h"
- struct AST* parse_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
if(translation_data->tokens->size==0)
return (struct AST*)get_error_tree(NULL);
case KW_OPEN_CURLY:
chomp(translation_data);
- return parse_finish_compound_statement(translation_data,scope);
+ return parse_finish_compound_statement(translation_data,scope,upper_loop,upper_switch);
case KW_IF:
chomp(translation_data);
- return parse_finish_if_statement(translation_data,scope);
+ return parse_finish_if_statement(translation_data,scope,upper_loop,upper_switch);
case KW_SWITCH:
chomp(translation_data);
- return parse_finish_switch_statement(translation_data,scope);
+ return parse_finish_switch_statement(translation_data,scope,upper_loop,upper_switch);
case KW_WHILE:
chomp(translation_data);
- return parse_finish_while_statement(translation_data,scope);
+ return parse_finish_while_statement(translation_data,scope,upper_loop,upper_switch);
case KW_DO:
chomp(translation_data);
- return parse_finish_do_while_statement(translation_data,scope);
+ return parse_finish_do_while_statement(translation_data,scope,upper_loop,upper_switch);
case KW_FOR:
chomp(translation_data);
- return parse_finish_for_statement(translation_data,scope);
+ return parse_finish_for_statement(translation_data,scope,upper_loop,upper_switch);
case KW_GOTO:
chomp(translation_data);
- return parse_finish_goto_statement(translation_data,scope);
+ return parse_finish_goto_statement(translation_data,scope,upper_loop,upper_switch);
case KW_CASE:
chomp(translation_data);
- return parse_finish_labeled_statement(translation_data,scope,ST_CASE);
+ return parse_finish_case_statement(translation_data,scope,upper_loop,upper_switch);
case KW_DEFAULT:
chomp(translation_data);
- return parse_finish_default_statement(translation_data,scope);
+ return parse_finish_default_statement(translation_data,scope,upper_loop,upper_switch);
case KW_ID:
if(check(translation_data,KW_COLUMN,1))
{
- return parse_finish_labeled_statement(translation_data,scope,ST_LABEL);
+ return parse_finish_labeled_statement(translation_data,scope,ST_LABEL,upper_loop,upper_switch);
}else
{
- return parse_expression_statement(translation_data,scope);
+ return parse_expression_statement(translation_data,scope,upper_loop,upper_switch);
}
case KW_CONTINUE:
chomp(translation_data);
- return parse_finish_continue_statement(translation_data);
+ return parse_finish_continue_statement(translation_data,upper_loop,upper_switch);
case KW_BREAK:
chomp(translation_data);
- return parse_finish_break_statement(translation_data);
+ return parse_finish_break_statement(translation_data,upper_loop,upper_switch);
case KW_RETURN:
chomp(translation_data);
- return parse_finish_return_statement(translation_data,scope);
+ return parse_finish_return_statement(translation_data,scope,upper_loop,upper_switch);
default:
- return parse_expression_statement(translation_data,scope);
+ return parse_expression_statement(translation_data,scope,upper_loop,upper_switch);
}
/*
( declaration | statement )* }
*/
- struct AST* parse_finish_compound_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_finish_compound_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST_Compound_Statement *hold;
hold=get_compound_statement_tree(scope);
parse_declaration(translation_data,hold->scope,&hold->components,0);
}else
{
- Queue_Push(&hold->components,parse_statement(translation_data,hold->scope));
+ Queue_Push(&hold->components,parse_statement(translation_data,hold->scope,upper_loop,upper_switch));
}
if(has_new_errors(translation_data))
chase_next_semicolumn(translation_data);
( expression ) statement
( expression ) statement else statement
*/
- struct AST* parse_finish_if_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_finish_if_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST_If_Statement *hold;
hold=get_if_statement_tree();
hold->condition=parse_expression(translation_data,scope);
if(get_and_check(translation_data,KW_CLOSE_NORMAL))
{
- hold->body_statement=parse_statement(translation_data,scope);
+ hold->body_statement=parse_statement(translation_data,scope,upper_loop,upper_switch);
}else
{
push_translation_error(" ')' expected",translation_data);
}
if(get_and_check(translation_data,KW_ELSE))
{
- hold->else_statement=parse_statement(translation_data,scope);
+ hold->else_statement=parse_statement(translation_data,scope,upper_loop,upper_switch);
return (struct AST*)hold;
}else
{
/*
( expression ) statement
*/
- struct AST* parse_finish_switch_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_finish_switch_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST_Switch_Statement *hold;
hold=get_switch_statement_tree();
hold->condition=parse_expression(translation_data,scope);
if(get_and_check(translation_data,KW_CLOSE_NORMAL))
{
- hold->body_statement=parse_statement(translation_data,scope);
+ hold->body_statement=parse_statement(translation_data,scope,upper_loop,hold);
}else
{
push_translation_error(" ')' expected",translation_data);
( expression ) statement
*/
- struct AST* parse_finish_while_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_finish_while_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST_While_Statement *hold;
hold=get_while_statement_tree();
hold->condition=parse_expression(translation_data,scope);
if(get_and_check(translation_data,KW_CLOSE_NORMAL))
{
- hold->body_statement=parse_statement(translation_data,scope);
+ hold->body_statement=parse_statement(translation_data,scope,(struct AST*)hold,upper_switch);
}else
{
push_translation_error(" ')' expected",translation_data);
/*
statement while ( expression ) ;
*/
- struct AST* parse_finish_do_while_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_finish_do_while_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST_Do_While_Statement *hold;
hold=get_do_while_statement_tree();
- hold->body_statement=parse_statement(translation_data,scope);
+ hold->body_statement=parse_statement(translation_data,scope,(struct AST*)hold,upper_switch);
if(get_and_check(translation_data,KW_WHILE) && get_and_check(translation_data,KW_OPEN_NORMAL))
{
hold->condition=parse_expression(translation_data,scope);
/*
( [ expression ] ; [ expression ] ; [ expression ] ) statement
*/
- struct AST* parse_finish_for_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_finish_for_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST_For_Statement *hold;
hold=get_for_statement_tree();
return (struct AST*)get_error_tree((struct AST*)hold);
}
- hold->initialisation=parse_expression_statement(translation_data,scope);
- hold->condition=parse_expression_statement(translation_data,scope);
+ hold->initialisation=parse_expression_statement(translation_data,scope,upper_loop,upper_switch);
+ hold->condition=parse_expression_statement(translation_data,scope,upper_loop,upper_switch);
if(get_and_check(translation_data,KW_CLOSE_NORMAL))
{
hold->update=get_nop_tree();
return (struct AST*)get_error_tree((struct AST*)hold);
}
}
- hold->body_statement=parse_statement(translation_data,scope);
+ hold->body_statement=parse_statement(translation_data,scope,(struct AST*)hold,upper_switch);
return (struct AST*)hold;
}
/*
id ;
*/
- struct AST* parse_finish_goto_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_finish_goto_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST* ret;
/*
;
*/
- struct AST* parse_finish_continue_statement(struct Translation_Data* translation_data)
+ struct AST* parse_finish_continue_statement(struct Translation_Data* translation_data,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST *hold;
hold=malloc(sizeof(struct AST));
/*
;
*/
- struct AST* parse_finish_break_statement(struct Translation_Data* translation_data)
+ struct AST* parse_finish_break_statement(struct Translation_Data* translation_data,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST *hold;
hold=malloc(sizeof(struct AST));
id:
statement
*/
- struct AST* parse_finish_labeled_statement(struct Translation_Data* translation_data,struct Scope *scope,enum AST_Type type)
+ struct AST* parse_finish_labeled_statement(struct Translation_Data* translation_data,struct Scope *scope,enum AST_Type type,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST_Labeled_Statement *ret;
if(check(translation_data,KW_ID,0))
ret=get_labeled_statement_tree(Queue_Pop(translation_data->tokens),NULL,type,translation_data,scope);
if(get_and_check(translation_data,KW_COLUMN))
{
- ret->statement=parse_statement(translation_data,scope);
+ ret->statement=parse_statement(translation_data,scope,upper_loop,upper_switch);
return (struct AST*)ret;
}else
{
return (struct AST*)get_error_tree(NULL);
}
}
+
+ /*
+ expression :
+ statement
+
+
+ */
+ struct AST* parse_finish_case_statement(struct Translation_Data *translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
+ {
+
+ }
/*
:
statement
*/
- struct AST* parse_finish_default_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_finish_default_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST_Labeled_Statement *ret;
ret=get_labeled_statement_tree(NULL,NULL,ST_DEFAULT,translation_data,scope);
if(get_and_check(translation_data,KW_COLUMN))
{
- ret->statement=parse_statement(translation_data,scope);
+ ret->statement=parse_statement(translation_data,scope,upper_loop,upper_switch);
return (struct AST*)ret;
}else
{
[ expression ] ;
*/
- struct AST* parse_finish_return_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_finish_return_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST_Return_Statement *hold;
if(get_and_check(translation_data,KW_SEMI_COLUMN))
[ expression ] ;
*/
- struct AST* parse_expression_statement(struct Translation_Data* translation_data,struct Scope *scope)
+ struct AST* parse_expression_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch)
{
struct AST *hold;
if(get_and_check(translation_data,KW_SEMI_COLUMN))
F diff --git a/src/frontend/parse/parse_statement.h b/src/frontend/parse/parse_statement.h
--- a/src/frontend/parse/parse_statement.h
+++ b/src/frontend/parse/parse_statement.h
#include <program.h>
- struct AST* parse_statement(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_finish_compound_statement(struct Translation_Data* translation_data,struct Scope *scope);
- //struct AST* parse_op_e_cl_st(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_finish_if_statement(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_finish_switch_statement(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_finish_do_while_statement(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_finish_while_statement(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_finish_for_statement(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_finish_goto_statement(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_finish_continue_statement(struct Translation_Data* translation_data);
- struct AST* parse_finish_break_statement(struct Translation_Data* translation_data);
- struct AST* parse_finish_return_statement(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_expression_statement(struct Translation_Data* translation_data,struct Scope *scope);
- struct AST* parse_finish_labeled_statement(struct Translation_Data* translation_data,struct Scope *scope,enum AST_Type type);
- struct AST* parse_finish_default_statement(struct Translation_Data* translation_data,struct Scope *scope);
+
+ struct AST* parse_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_compound_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_if_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_switch_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_do_while_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_while_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_for_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_goto_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_continue_statement(struct Translation_Data* translation_data,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_break_statement(struct Translation_Data* translation_data,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_return_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_expression_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+ struct AST* parse_finish_labeled_statement(struct Translation_Data* translation_data,struct Scope *scope,enum AST_Type type,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+
+ struct AST* parse_finish_case_statement(struct Translation_Data *translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
+
+ struct AST* parse_finish_default_statement(struct Translation_Data* translation_data,struct Scope *scope,struct AST *upper_loop,struct AST_Switch_Statement *upper_switch);
void chase_next_semicolumn(struct Translation_Data *translation_data);