From ac720e3239080628cdcfa0016d70959334f1294e Mon Sep 17 00:00:00 2001 From: serr Date: Tue, 20 May 2025 17:45:47 +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=80=D0=B0=D0=B7=D0=BD=D1=8B=D0=B5=20=D1=81=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D0=BE=D0=B1=D1=8B=20=D0=B4=D0=B5=D0=BA=D0=BB=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D1=81=D0=BA=D0=B8=D1=85=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=D0=BE=D0=B2=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82?= =?UTF-8?q?=D1=83=D1=80=20=D0=B8=20=D0=BE=D0=B1=D1=80=D0=B0=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=20=D0=BF=D0=BE=D0=BB=D1=8E=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyzers/test/test.y | 45 ++++++++++++++++++++++++------------------- tests/main.go | 2 -- tests/test_types.txt | 31 +++++++++++++++++++++++------ 3 files changed, 50 insertions(+), 28 deletions(-) diff --git a/analyzers/test/test.y b/analyzers/test/test.y index 9de6b2c..50ab97f 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -83,7 +83,7 @@ block: ; any_identifier: - IDENTIFIER + IDENTIFIER | WITH_DOT_IDENTIFIER // @@ -203,19 +203,19 @@ expr: ; math_expr: - IDENTIFIER ASSIGN math_expr { } - | IDENTIFIER PLUS_EQ math_expr - | IDENTIFIER MINUS_EQ math_expr - | IDENTIFIER MUL_EQ math_expr - | IDENTIFIER DIV_EQ math_expr + any_identifier ASSIGN math_expr { } + | any_identifier PLUS_EQ math_expr + | any_identifier MINUS_EQ math_expr + | any_identifier MUL_EQ math_expr + | any_identifier DIV_EQ math_expr - | IDENTIFIER MOD_EQ math_expr - | IDENTIFIER AMPERSAND_EQ math_expr - | IDENTIFIER PIPE_EQ math_expr - | IDENTIFIER XOR_EQ math_expr - | IDENTIFIER LSHIFT_EQ math_expr - | IDENTIFIER RSHIFT_EQ math_expr - | IDENTIFIER AND_NOT_EQ math_expr + | any_identifier MOD_EQ math_expr + | any_identifier AMPERSAND_EQ math_expr + | any_identifier PIPE_EQ math_expr + | any_identifier XOR_EQ math_expr + | any_identifier LSHIFT_EQ math_expr + | any_identifier RSHIFT_EQ math_expr + | any_identifier AND_NOT_EQ math_expr | math_expr PLUS math_expr { printf("PLUS\n"); } | math_expr MINUS math_expr { printf("MINUS\n"); } @@ -227,9 +227,9 @@ math_expr: | NUMBER { printf("NUMBER\n"); } | FLOAT_LITERAL { printf("FLOAT LITERAL\n"); } | COMPLEX_LITERAL { printf("COMPLEX LITERAL\n"); } - | IDENTIFIER { printf("IDENTIFIER: %s\n", $1); } - | IDENTIFIER INC { printf("POST-INCREMENT: %s++\n", $1); } - | IDENTIFIER DEC { printf("POST-DECREMENT: %s--\n", $1); } + | any_identifier { printf("IDENTIFIER\n"); } + | any_identifier INC { printf("POST-INCREMENT: ++\n"); } + | any_identifier DEC { printf("POST-DECREMENT: --\n"); } | func_call { printf("FUNCTION CALL IN EXPR\n"); } ; @@ -386,7 +386,7 @@ field_list: | field_list COMMA field struct_literal: - IDENTIFIER LBRACE field_list RBRACE { printf("STRUCT LITERAL\n"); } + any_identifier LBRACE field_list RBRACE { printf("STRUCT LITERAL\n"); } // // vars decl @@ -394,9 +394,14 @@ var_multiple_short_declaration: identifiers_list SHORT_DECLARATION math_expr_or_literals_list var_declaration: - VAR IDENTIFIER type { { printf("\033[1;33mVAR DECL without init value: %s\n\033[0m", $2); } } - | VAR IDENTIFIER type ASSIGN math_expr { { printf("\033[1;33mVAR DECL with math expr init value: %s\n\033[0m", $2); } } - | VAR IDENTIFIER type ASSIGN literal { { printf("\033[1;33mVAR DECL with literal init value: %s\n\033[0m", $2); } } + VAR IDENTIFIER any_identifier { { printf("\033[1;33mVAR DECL without init value: %s\n\033[0m", $2); } } + | VAR IDENTIFIER type { { printf("\033[1;33mVAR DECL without init value: %s\n\033[0m", $2); } } + | VAR IDENTIFIER ASSIGN math_expr { { printf("\033[1;33mVAR DECL with math expr init value: %s\n\033[0m", $2); } } + | VAR IDENTIFIER ASSIGN literal { { printf("\033[1;33mVAR DECL with literal init value: %s\n\033[0m", $2); } } + | VAR IDENTIFIER any_identifier ASSIGN math_expr { { printf("\033[1;33mVAR DECL with type and math expr init value: %s\n\033[0m", $2); } } + | VAR IDENTIFIER any_identifier ASSIGN literal { { printf("\033[1;33mVAR DECL with type and literal init value: %s\n\033[0m", $2); } } + | VAR IDENTIFIER type ASSIGN math_expr { { printf("\033[1;33mVAR DECL with type and math expr init value: %s\n\033[0m", $2); } } + | VAR IDENTIFIER type ASSIGN literal { { printf("\033[1;33mVAR DECL with type and literal init value: %s\n\033[0m", $2); } } ; // type decl diff --git a/tests/main.go b/tests/main.go index 5b18539..72c3a2b 100644 --- a/tests/main.go +++ b/tests/main.go @@ -29,9 +29,7 @@ func ujas() (func() func() func() int, int, string) { func main() { a := "Tom" - var tom = person{name: a, age: 24} - a := 1e6 fmt.Println(a) arr := []int{1, 2, 3} for idx, val := range arr { diff --git a/tests/test_types.txt b/tests/test_types.txt index 9f6b5bd..5555cb6 100644 --- a/tests/test_types.txt +++ b/tests/test_types.txt @@ -1,5 +1,10 @@ package main; -import "fmt"; +import ( + "fmt"; + "your_project/models"; +) + + type mile uint; type BinaryOp func(int, int) int; @@ -8,15 +13,29 @@ type empty struct{ }; type person struct{ - name, second_name string; - age int; - work func() + name string; + age int }; func main() { - d := "Debilov"; - tom := person {name: "Tom", second_name: d, age: 20+2*2}; + undefined := person {}; + var alice person = person{age: 23, name: "Alice"}; + var tom = person {name: "Tom", age: 24}; + var tom1 Person = Person{Name: "Tom", Age: 24}; + tom2 := Person{Name: "Tom", Age: 24}; + // Явное указание типа с пакетом + var tom3 models.Person = models.Person{Name: "Tom", Age: 24}; + // Краткая форма + tom4 := models.Person{Name: "Tom", Age: 24}; + // Вывод типа + var tom5 = models.Person{Name: "Tom", Age: 24}; + + fmt.Println(tom.name); // Tom + fmt.Println(tom.age); // 24 + + tom.age = 38; // изменяем значение + fmt.Println(tom.name, tom.age); // Tom 38 } \ No newline at end of file