From 51a96ccd5f47b2cc9d7cbf07aefeab8f06ae081f Mon Sep 17 00:00:00 2001 From: serr Date: Sun, 18 May 2025 20:30:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BE=D0=BF=D1=80=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=82=D0=B8=D0=BF=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyzers/test/test.l | 1 + analyzers/test/test.y | 12 +++++++++--- tests/main.go | 4 ++++ tests/test_funcs.txt | 24 +++++++++++++----------- tests/test_types.txt | 5 +++++ 5 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 tests/test_types.txt diff --git a/analyzers/test/test.l b/analyzers/test/test.l index af0cab3..b5ee1ce 100644 --- a/analyzers/test/test.l +++ b/analyzers/test/test.l @@ -72,6 +72,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] "++" { return INC; } "--" { return DEC; } +"type" { return TYPE; } "go" { return GO; } "defer" { return DEFER; } "range" { return RANGE; } diff --git a/analyzers/test/test.y b/analyzers/test/test.y index f10b126..fc707d8 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -25,7 +25,7 @@ void free_node(char *str) { %token VAR FUNC RETURN STRING_LITERAL FLOAT_LITERAL COMPLEX_LITERAL NUMBER PACKAGE IMPORT %token INC DEC PLUS_EQ MINUS_EQ MUL_EQ DIV_EQ MOD_EQ %token AMPERSAND_EQ PIPE_EQ XOR_EQ LSHIFT_EQ RSHIFT_EQ AND_NOT_EQ -%token FOR BREAK CONTINUE ARROW IF ELSE RANGE DEFER GO +%token FOR BREAK CONTINUE ARROW IF ELSE RANGE DEFER GO TYPE %token CHAN CONST CASE SWITCH %token PLUS MINUS MULT DIV MOD %token STRING @@ -68,6 +68,8 @@ statement: { printf("\033[1;33mSTATEMENT: variable multiple declaration\033[0m\n"); } | func_declaration { printf("\033[1;33mSTATEMENT: function declaration\033[0m\n"); } + | type_delcaration SEMICOLON + { printf("\033[1;33mSTATEMENT: type declaration\033[0m\n"); } | cicle { printf("\033[1;33mSTATEMENT: cicle\033[0m\n"); } | condition @@ -93,7 +95,7 @@ statements_list: ; identifiers_list: - IDENTIFIER { } + | IDENTIFIER { } | identifiers_list COMMA IDENTIFIER { } math_expr_or_literals_list: @@ -278,7 +280,7 @@ string_types: ; func_types: - FUNC LPAREN RPAREN return_type + FUNC LPAREN arg_list RPAREN return_type type: int_types { } @@ -372,6 +374,10 @@ var_declaration: | VAR IDENTIFIER type ASSIGN literal { { printf("\033[1;33mVAR DECL with literal init value: %s\n\033[0m", $2); } } ; +// type decl +type_delcaration: + TYPE IDENTIFIER type { { printf("\033[1;33mTYPE DECL\n\033[0m"); } } + %% // diff --git a/tests/main.go b/tests/main.go index 74b8624..c4a180d 100644 --- a/tests/main.go +++ b/tests/main.go @@ -5,6 +5,10 @@ import ( "log" ) +func test(int, int) { + +} + func ujas() (func() func() func() int, int, string) { return func() func() func() int { return func() func() int { diff --git a/tests/test_funcs.txt b/tests/test_funcs.txt index d7060a2..dc1cd14 100644 --- a/tests/test_funcs.txt +++ b/tests/test_funcs.txt @@ -9,19 +9,21 @@ func server(a int) { } func iife(work int) { + + for i := 1; i < 3; i++ { + func(){}(); + func(){fmt.Println(123);}(); - func(){}(); - func(){fmt.Println(123);}(); + go func(a, b string) { + fmt.Println("Message:", a + b); + }("Hello", ", world!"); - go func(a, b string) { - fmt.Println("Message:", a + b); - }("Hello", ", world!"); - - defer func() { - if err := recover(); err != nil { - go log.Println("work failed:", err); - } - }(); + defer func() { + if err := recover(); err != nil { + go log.Println("work failed:", err); + } + }(); + } } func ujas() (func() func() func() int, int, string) { diff --git a/tests/test_types.txt b/tests/test_types.txt new file mode 100644 index 0000000..a9aaa7d --- /dev/null +++ b/tests/test_types.txt @@ -0,0 +1,5 @@ +package main; +import "fmt"; + +type mile uint; +type BinaryOp func(int, int) int; \ No newline at end of file