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