diff --git a/analyzers/test/test.y b/analyzers/test/test.y index 67076c0..0f37f74 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -98,6 +98,10 @@ identifiers_list: | IDENTIFIER { } | identifiers_list COMMA IDENTIFIER { } +any_identifiers_list: + | any_identifier { } + | any_identifiers_list COMMA any_identifier { } + math_expr_or_literals_list: literal { } | math_expr { } @@ -395,10 +399,13 @@ var_multiple_short_declaration: identifiers_list SHORT_DECLARATION math_expr_or_literals_list var_declaration: - 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 type + | VAR IDENTIFIER any_identifier + | VAR identifiers_list any_identifier { { printf("\033[1;33mVAR DECL without init value\n\033[0m"); } } + | VAR identifiers_list type { { printf("\033[1;33mVAR DECL without init value\n\033[0m"); } } + | VAR identifiers_list ASSIGN math_expr_or_literals_list { { printf("\033[1;33mVAR DECL with literal init value\n\033[0m"); } } + | VAR identifiers_list type ASSIGN math_expr_or_literals_list { { printf("\033[1;33mVAR DECL with literal init value\n\033[0m"); } } + | VAR identifiers_list any_identifier ASSIGN math_expr_or_literals_list { { printf("\033[1;33mVAR DECL with literal init value\n\033[0m"); } } | 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); } } diff --git a/tests/main.go b/tests/main.go index bc21c4b..b39b6ce 100644 --- a/tests/main.go +++ b/tests/main.go @@ -27,8 +27,8 @@ func ujas() (func() func() func() int, int, string) { }, 1, "hello world" } func main() { - a := "Tom" + fmt.Println(a) arr := []int{1, 2, 3} for idx, val := range arr { diff --git a/tests/test_multiple_declaration.txt b/tests/test_multiple_declaration.txt index 99dea9e..b2a097d 100644 --- a/tests/test_multiple_declaration.txt +++ b/tests/test_multiple_declaration.txt @@ -9,6 +9,13 @@ func test() { a := 1; // декларация одной переменной (число) a := "test"; // декларация одной переменной (строка) + var a, b, c, d int; + + var a = 2+2*2; + + var a, b, c, d = 1,2,3,4; + var a, b, c, d int = 1,2,3,4; + a, b := 1, 2; // декларация нескольких переменных (целые литералы) a, b := b, a; // swap a, b := "hello", "sailor"; // декларация нескольких переменных (строковые литералы) diff --git a/tests/test_types.txt b/tests/test_types.txt index 9dd6e47..085b0dc 100644 --- a/tests/test_types.txt +++ b/tests/test_types.txt @@ -16,14 +16,24 @@ type person struct{ name string; age int }; +type person2 struct{ + name,second_name string; + age int +}; + func main() { + var p models.Person; + var a,b,c,d models.Person; + var a,b,c models.Person = models.Person{"Tom", 24}, models.Person{"Tom", 24}, models.Person{"Tom", 24}; + + var p models.Person = person{}; p1 := models.Person{"Tom", 24}; - undefined := person {}; + a, undefined := 1, person {}; var alice person = person{age: 23, name: "Alice"}; var tom = person {name: "Tom", age: 24};