Progrès
This commit is contained in:
parent
77ddf1514a
commit
9266d5fc27
3 changed files with 14 additions and 7 deletions
|
@ -14,6 +14,8 @@ ASTStack *stack;
|
|||
|
||||
void yyerror(char *s);
|
||||
|
||||
Tag ntag = {0,T_null};
|
||||
|
||||
int make_stack(){
|
||||
stack = malloc(sizeof(ASTStack)+sizeof(Statement)*2048);
|
||||
if(!stack)
|
||||
|
@ -53,13 +55,15 @@ Statement *make_iconst(i32 val){
|
|||
}
|
||||
|
||||
Statement *declare(i32 type, Tag vtype, char *name){
|
||||
puts("declare");
|
||||
i32 len = strcspn(name, " \t\n)");
|
||||
char *name2 = strndup(name, len);
|
||||
printf("declare : %s\n", name2);
|
||||
Statement *stat = &stack->statements[stack->curr_statement++];
|
||||
stat->type = type;
|
||||
if(hashmap_get(&stack->symbol_map, name)){
|
||||
if(hashmap_get(&stack->symbol_map, name2)){
|
||||
yyerror("Redeclaring existing identifier");
|
||||
}
|
||||
MapItem *ret = hashmap_insert(&stack->symbol_map, name);
|
||||
MapItem *ret = hashmap_insert(&stack->symbol_map, name2);
|
||||
ret->type = *((i32*)&vtype);
|
||||
stat->var_id = ret->id;
|
||||
stat->var_type = vtype;
|
||||
|
|
|
@ -28,3 +28,5 @@ Statement *make_operation(i32 type, i32 extainf, char *str, i32 nparam,
|
|||
Statement *param, ...);
|
||||
|
||||
void set_entry_point(Statement *statement);
|
||||
|
||||
extern Tag ntag;
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
Tag tag;
|
||||
}
|
||||
|
||||
%token <str> G_IDENT TYPE_U
|
||||
%nonassoc <str> G_IDENT
|
||||
%token <str> TYPE_U
|
||||
%token VEC
|
||||
%token VAR
|
||||
%token LET
|
||||
|
@ -59,13 +60,13 @@ expr:
|
|||
'(' G_IDENT ')'
|
||||
{$$ = make_operation(ST_Call, 0, $2, 0, NULL);}
|
||||
| '(' VAR G_IDENT ')'
|
||||
{Tag ntag = {0,T_null}; $$ = declare(BI_var,ntag,$3);}
|
||||
{ $$ = declare(BI_var,ntag,$3);}
|
||||
| '(' VAR type G_IDENT ')'
|
||||
{$$ = declare(BI_var, $3, $4);}
|
||||
| '(' VAR G_IDENT expr')'
|
||||
{}
|
||||
{$$ = declare(BI_var,ntag,$4);}
|
||||
| '(' VAR type G_IDENT expr ')'
|
||||
{}
|
||||
{$$ = declare(BI_var,$3,$4);}
|
||||
| '(' LET G_IDENT ')'
|
||||
{}
|
||||
| '(' LET type G_IDENT ')'
|
||||
|
|
Loading…
Add table
Reference in a new issue