fix parse and semantic v2.1

This commit is contained in:
2025-12-05 00:47:51 +09:00
parent 2b6193a2c7
commit d46fd36bcb
4 changed files with 51 additions and 20 deletions

View File

@@ -18,7 +18,7 @@ static int savedNumber;
static int savedLineNo; /* ditto */
static TreeNode * savedTree; /* stores syntax tree for later return */
static int yylex(void); // added 11/2/11 to ensure no conflict with lex
int yyerror(char * message);
%}
%token IF ELSE WHILE RETURN INT VOID
@@ -120,13 +120,16 @@ param_list : param_list COMMA param {
} | param {$$ = $1; };
param : type_specifier name_specifier {
$$ = newDeclNode(NonArrParamK );
$$ = newDeclNode(NonArrParamK);
$$->attr.name = savedName;
$$->type = $1->type;
} | type_specifier name_specifier LBRACE RBRACE {
$$ = newDeclNode(ArrParamK);
$$->type = $1->type;
$$->attr.name = savedName;
if ($1->type == Integer)
$$->type = IntegerArray;
else
$$->type = Void;
};
compound_stmt : LCURLY local_declarations statement_list RCURLY {