|
|
|
@ -7,6 +7,8 @@
|
|
|
|
|
#include "ast.h" |
|
|
|
|
#include "mem.h" |
|
|
|
|
|
|
|
|
|
extern int yylineno; |
|
|
|
|
|
|
|
|
|
ast_list *make_list(ast *elem, ast_list *tail) |
|
|
|
|
{ |
|
|
|
|
ast_list *list = safe_malloc(sizeof(ast_list)); |
|
|
|
@ -39,6 +41,7 @@ ast *make_list_node(ast_list *list)
|
|
|
|
|
elem->tag = node_ast; |
|
|
|
|
elem->info.node.tag = kind_list; |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -49,6 +52,7 @@ ast *make_string(char *string)
|
|
|
|
|
|
|
|
|
|
elem->tag = str_ast; |
|
|
|
|
elem->info.string = string; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -59,6 +63,7 @@ ast *make_integer(long integer)
|
|
|
|
|
|
|
|
|
|
elem->tag = int_ast; |
|
|
|
|
elem->info.integer = integer; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -69,6 +74,7 @@ ast *make_real(float real)
|
|
|
|
|
|
|
|
|
|
elem->tag = real_ast; |
|
|
|
|
elem->info.real = real; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -84,6 +90,7 @@ ast *make_function(char *identifier, ast_list *args, ast_list *stmts)
|
|
|
|
|
list = make_list(make_list_node(args), list); |
|
|
|
|
list = make_list(make_string(identifier), list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -98,6 +105,7 @@ ast *make_fndefint(char *identifier, long num)
|
|
|
|
|
list = make_list(make_integer(num), list); |
|
|
|
|
list = make_list(make_string(identifier), list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -112,6 +120,7 @@ ast *make_constant(char *identifier, long num)
|
|
|
|
|
list = make_list(make_integer(num), list); |
|
|
|
|
list = make_list(make_string(identifier), list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -126,6 +135,7 @@ ast *make_realconstant(char *identifier, float num)
|
|
|
|
|
list = make_list(make_real(num), list); |
|
|
|
|
list = make_list(make_string(identifier), list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -139,6 +149,7 @@ ast *make_fndefext(char *identifier)
|
|
|
|
|
elem->info.node.tag = kind_fndefext; |
|
|
|
|
list = make_list(make_string(identifier), list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -149,6 +160,7 @@ ast *make_variable(char *identifier)
|
|
|
|
|
|
|
|
|
|
elem->tag = var_ast; |
|
|
|
|
elem->info.variable = identifier; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -163,6 +175,7 @@ ast *make_array(char *identifier, ast *expression)
|
|
|
|
|
list = make_list(expression, NULL); |
|
|
|
|
list = make_list(make_variable(identifier), list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -178,6 +191,7 @@ ast *make_assignment(char *identifier, ast *expression)
|
|
|
|
|
list = make_list(expression, NULL); |
|
|
|
|
list = make_list(make_variable(identifier), list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -193,6 +207,7 @@ ast *make_assignment(ast_list *identifier_list, ast *expression)
|
|
|
|
|
list = make_list(expression, NULL); |
|
|
|
|
list = make_list(make_list_node(identifier_list), list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -207,6 +222,7 @@ ast *make_binary_op(ast_kind op, ast *exp1, ast *exp2)
|
|
|
|
|
list = make_list(exp2, NULL); |
|
|
|
|
list = make_list(exp1, list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -220,6 +236,7 @@ ast *make_unary_op(ast_kind op, ast *exp1)
|
|
|
|
|
elem->info.node.tag = op; |
|
|
|
|
list = make_list(exp1, NULL); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -234,6 +251,7 @@ ast *make_call(char *identifier, ast_list *args)
|
|
|
|
|
list = make_list(make_list_node(args), NULL); |
|
|
|
|
list = make_list(make_string(identifier), list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -252,6 +270,7 @@ ast *make_statement(ast_kind type, ast *expression, ast_list *statements,
|
|
|
|
|
list = make_list(make_list_node(statements), list); |
|
|
|
|
list = make_list(expression, list); |
|
|
|
|
elem->info.node.head = list; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -262,6 +281,7 @@ ast *make_case_statement_variable(char *identifier)
|
|
|
|
|
|
|
|
|
|
elem->tag = casevar_ast; |
|
|
|
|
elem->info.variable = identifier; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -272,6 +292,7 @@ ast *make_case_statement_number(long num)
|
|
|
|
|
|
|
|
|
|
elem->tag = casenum_ast; |
|
|
|
|
elem->info.integer = num; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -283,6 +304,7 @@ ast *make_return_statement(void)
|
|
|
|
|
elem->tag = node_ast; |
|
|
|
|
elem->info.node.tag = stmt_return; |
|
|
|
|
elem->info.node.head = NULL; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -294,6 +316,7 @@ ast *make_break_statement(void)
|
|
|
|
|
elem->tag = node_ast; |
|
|
|
|
elem->info.node.tag = stmt_break; |
|
|
|
|
elem->info.node.head = NULL; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
@ -305,6 +328,7 @@ ast *make_default_statement(void)
|
|
|
|
|
elem->tag = node_ast; |
|
|
|
|
elem->info.node.tag = stmt_default; |
|
|
|
|
elem->info.node.head = NULL; |
|
|
|
|
elem->lineno = yylineno; |
|
|
|
|
|
|
|
|
|
return elem; |
|
|
|
|
} |
|
|
|
|