добавил структурный литерал

master2
serr 2025-05-18 21:12:50 +03:00
parent 4145259d12
commit dbe1ff7d32
3 changed files with 29 additions and 4 deletions

View File

@ -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

View File

@ -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}

View File

@ -12,3 +12,11 @@ type person struct{
age int;
work func()
};
func main() {
d := "Debilov";
tom := person {name: "Tom", second_name: d, age: 20+2*2};
}