X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fparser_proc.y;h=06e4be59a4cd9c314d4bd49db3d118a0eed393ff;hb=6bc2d7ee8421401fc11225e09e4bb1fab03594b8;hp=c90062a365e1b1cd2b18a105337b87d797668dc2;hpb=58066949f02dbdbc3ba7b3fa3a0e01836fa72663;p=m6w6%2Fext-psi diff --git a/src/parser_proc.y b/src/parser_proc.y index c90062a..06e4be5 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -349,6 +349,24 @@ impl_stmt(stmt) ::= free_stmt(free). { stmt = init_impl_stmt(PSI_T_FREE, free); } +%token_class num_exp_token NUMBER NSNAME. +%token_class num_exp_op_token PLUS MINUS ASTERISK SLASH. +%type num_exp {num_exp*} +%destructor num_exp {free_num_exp($$);} +num_exp(exp) ::= num_exp_token(tok). { + exp = init_num_exp(tok->type, tok->text); + free(tok); +} +num_exp(exp) ::= decl_var(var). { + exp = init_num_exp(PSI_T_NAME, var); +} +num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). { + exp_->operator = operator_->type; + exp_->operand = operand_; + exp = exp_; + free(operator_); +} + %type let_stmt {let_stmt*} %destructor let_stmt {free_let_stmt($$);} let_stmt(let) ::= LET decl_var(var) EOS. { @@ -357,38 +375,26 @@ let_stmt(let) ::= LET decl_var(var) EOS. { let_stmt(let) ::= LET decl_var(var) EQUALS let_value(val) EOS. { let = init_let_stmt(var, val); } +let_stmt(let) ::= decl_arg(arg) EQUALS decl_var(var_) EOS. { + let = init_let_stmt(arg->var, NULL); +} %type let_value {let_value*} %destructor let_value {free_let_value($$);} -let_value(val) ::= CALLOC(F) LPAREN let_calloc(alloc) RPAREN. { - val = init_let_value(init_let_func(F->type, F->text, alloc), NULL, 0); +let_value(val) ::= reference(r) CALLOC(F) LPAREN let_calloc(alloc) RPAREN. { + val = init_let_value(init_let_func(F->type, F->text, alloc), NULL, r); free(F); } - %type let_calloc {let_calloc*} %destructor let_calloc {free_let_calloc($$);} let_calloc(alloc) ::= num_exp(nmemb) COMMA num_exp(size). { alloc = init_let_calloc(nmemb, size); } -%token_class num_exp_token NUMBER NSNAME. -%token_class num_exp_op_token PLUS MINUS ASTERISK SLASH. -%type num_exp {num_exp*} -%destructor num_exp {free_num_exp($$);} -num_exp(exp) ::= num_exp_token(tok). { - exp = init_num_exp(tok->type, tok->text); - free(tok); -} -num_exp(exp) ::= decl_var(var). { - exp = init_num_exp(PSI_T_NAME, var); -} -num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). { - exp_->operator = operator_->type; - exp_->operand = operand_; - exp = exp_; - free(operator_); +let_value(val) ::= reference(r) num_exp(exp). { + val = init_let_value(NULL, NULL, r); + val->num = exp; } - let_value(val) ::= reference(r) let_func(func) LPAREN impl_var(var) RPAREN. { val = init_let_value(func, var, r); }