From dbe1ff7d3292d302079281c0530454370622710b Mon Sep 17 00:00:00 2001 From: serr Date: Sun, 18 May 2025 21:12:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D0=BB=D0=B8=D1=82=D0=B5=D1=80=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyzers/test/test.y | 19 ++++++++++++++++--- tests/main.go | 4 ++++ tests/test_types.txt | 10 +++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/analyzers/test/test.y b/analyzers/test/test.y index 02af1a3..9de6b2c 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -252,7 +252,7 @@ log_expr: // types struct_types: - STRUCT LBRACE field_list RBRACE + STRUCT LBRACE declarate_field_list RBRACE ; bool_types: @@ -302,6 +302,7 @@ type: // literals literal: STRING_LITERAL { } + | struct_literal { } | func_literal { } | COMPLEX_LITERAL { } | BOOL_LITERAL { } @@ -370,10 +371,22 @@ func_declaration: // // struct -field_list: +declarate_field_list: | arg_declaration - | field_list SEMICOLON arg_declaration + | declarate_field_list SEMICOLON arg_declaration ; + +field: + IDENTIFIER COLON literal { } + | IDENTIFIER COLON math_expr { } + | IDENTIFIER COLON func_call { } + +field_list: + | field + | field_list COMMA field + +struct_literal: + IDENTIFIER LBRACE field_list RBRACE { printf("STRUCT LITERAL\n"); } // // vars decl diff --git a/tests/main.go b/tests/main.go index e6c8181..5b18539 100644 --- a/tests/main.go +++ b/tests/main.go @@ -27,6 +27,10 @@ func ujas() (func() func() func() int, int, string) { }, 1, "hello world" } func main() { + + a := "Tom" + var tom = person{name: a, age: 24} + a := 1e6 fmt.Println(a) arr := []int{1, 2, 3} diff --git a/tests/test_types.txt b/tests/test_types.txt index c312b9b..9f6b5bd 100644 --- a/tests/test_types.txt +++ b/tests/test_types.txt @@ -11,4 +11,12 @@ type person struct{ name, second_name string; age int; work func() -}; \ No newline at end of file +}; + +func main() { + + d := "Debilov"; + tom := person {name: "Tom", second_name: d, age: 20+2*2}; + + +} \ No newline at end of file