From: Ben Sherratt Date: Tue, 30 Jan 2024 18:09:04 +0000 (+0000) Subject: Fixed syntax for definitions X-Git-Url: https://git.bts.cx/sun.git/commitdiff_plain/dd54d29e3b6bb46b9c7233a14aa8e8db34340d87?ds=inline Fixed syntax for definitions --- diff --git a/runtime/src/sun/compiler/sun.y b/runtime/src/sun/compiler/sun.y index b71f4de..2464ffa 100644 --- a/runtime/src/sun/compiler/sun.y +++ b/runtime/src/sun/compiler/sun.y @@ -79,39 +79,39 @@ %% module - : optional_statements_or_definitions { + : optional_statements { $$ = sltNodeMakeModule($1); *moduleOut = $$; } ; -optional_statements_or_definitions - : /* Nothing */ { +/*optional_statements_or_definitions + : *//* Nothing *//* { $$ = NULL; } | statements_or_definitions ; statements_or_definitions - : definition { + : function_definition { $$ = sltNodeMakeSequence(NULL, $1); } | statement { $$ = sltNodeMakeSequence(NULL, $1); } - | statements_or_definitions definition { + | statements_or_definitions function_definition { $$ = sltNodeMakeSequence($1, $2); } | statements_or_definitions statement { $$ = sltNodeMakeSequence($1, $2); } - ; + ;*/ -definition +/*definition : function_definition - /*| type_definition*/ + | type_definition | variable_definition ';' - ; + ;*/ function_definition : IDENTIFIER IDENTIFIER '(' optional_parameter_definitions ')' '{' optional_statements '}' { @@ -198,6 +198,7 @@ statement : ';' { $$ = NULL; /* Otherwise this will pass up the ';' character */ } + | function_definition | variable_definition ';' | "return" optional_expression ';' { $$ = sltNodeMakeReturn($2);