добавил структурный литерал
parent
4145259d12
commit
dbe1ff7d32
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -11,4 +11,12 @@ type person struct{
|
|||
name, second_name string;
|
||||
age int;
|
||||
work func()
|
||||
};
|
||||
};
|
||||
|
||||
func main() {
|
||||
|
||||
d := "Debilov";
|
||||
tom := person {name: "Tom", second_name: d, age: 20+2*2};
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue