From c6aab10e74d58fbcad723c5f074a0bb51e9f2283 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 18:53:06 +0200 Subject: feat: add functions with defines params and return --- sfinae.y | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'sfinae.y') diff --git a/sfinae.y b/sfinae.y index 9fe994c..4e366a8 100644 --- a/sfinae.y +++ b/sfinae.y @@ -25,6 +25,11 @@ void yyerror(const char* message); %token TOK_UNDECLARE %token TOK_ENABLE_IF %token TOK_REPEAT +%token TOK_DEFINE +%token TOK_PARAMETERS +%token TOK_RETURN +%token TOK_INVOKE_RESULT +%token TOK_ARGUMENTS %token TOK_SEQUENCE %token TOK_NAME %token TOK_VALUE_OF @@ -55,7 +60,8 @@ void yyerror(const char* message); %token TOK_CHAR %type name char_list -%type statements statement sequence sequence_items type type_list value condition +%type statements statement sequence sequence_items parameters name_list +%type type type_list value condition %% @@ -84,9 +90,15 @@ statement { $$ = node_block(STMT_ENABLE_IF, $4, $6); } | TOK_COLONCOLON TOK_REPEAT '<' value ',' sequence '>' TOK_COLONCOLON TOK_COMMIT { $$ = node_block(STMT_REPEAT, $4, $6); } + | TOK_COLONCOLON TOK_DEFINE '<' name ',' parameters ',' sequence '>' TOK_COLONCOLON TOK_COMMIT + { + $$ = node_named(STMT_DEFINE, &$4, $6); + $$->body = $8; + } + | TOK_COLONCOLON TOK_RETURN '<' type '>' TOK_COLONCOLON TOK_COMMIT + { $$ = node_unary(STMT_RETURN, $4); } ; -// the statements inside are committed one by one, without the semicolons sequence : TOK_COLONCOLON TOK_SEQUENCE '<' sequence_items '>' { $$ = $4; } @@ -101,6 +113,20 @@ sequence_items { $$ = node_append($1, $3); } ; +parameters + : TOK_COLONCOLON TOK_PARAMETERS '<' name_list '>' + { $$ = $4; } + ; + +name_list + : /* nothing */ + { $$ = NULL; } + | name + { $$ = node_named(NODE_PARAMETER, &$1, NULL); } + | name_list ',' name + { $$ = node_append($1, node_named(NODE_PARAMETER, &$3, NULL)); } + ; + name : TOK_COLONCOLON TOK_NAME '<' char_list '>' { $$ = $4; } @@ -146,6 +172,9 @@ type { $$ = node_unary(TYPE_CHAR_CONSTANT, $7); } | TOK_COLONCOLON TOK_TUPLE '<' type_list '>' { $$ = node_unary(TYPE_TUPLE, $4); } + | TOK_COLONCOLON TOK_INVOKE_RESULT '<' name ',' + TOK_COLONCOLON TOK_ARGUMENTS '<' type_list '>' '>' + { $$ = node_named(TYPE_INVOKE, &$4, $9); } ; type_list -- cgit v1.3