добавил структурный литерал
parent
4145259d12
commit
dbe1ff7d32
|
@ -252,7 +252,7 @@ log_expr:
|
||||||
// types
|
// types
|
||||||
|
|
||||||
struct_types:
|
struct_types:
|
||||||
STRUCT LBRACE field_list RBRACE
|
STRUCT LBRACE declarate_field_list RBRACE
|
||||||
;
|
;
|
||||||
|
|
||||||
bool_types:
|
bool_types:
|
||||||
|
@ -302,6 +302,7 @@ type:
|
||||||
// literals
|
// literals
|
||||||
literal:
|
literal:
|
||||||
STRING_LITERAL { }
|
STRING_LITERAL { }
|
||||||
|
| struct_literal { }
|
||||||
| func_literal { }
|
| func_literal { }
|
||||||
| COMPLEX_LITERAL { }
|
| COMPLEX_LITERAL { }
|
||||||
| BOOL_LITERAL { }
|
| BOOL_LITERAL { }
|
||||||
|
@ -370,10 +371,22 @@ func_declaration:
|
||||||
//
|
//
|
||||||
|
|
||||||
// struct
|
// struct
|
||||||
field_list:
|
declarate_field_list:
|
||||||
| arg_declaration
|
| 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
|
// vars decl
|
||||||
|
|
|
@ -27,6 +27,10 @@ func ujas() (func() func() func() int, int, string) {
|
||||||
}, 1, "hello world"
|
}, 1, "hello world"
|
||||||
}
|
}
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
a := "Tom"
|
||||||
|
var tom = person{name: a, age: 24}
|
||||||
|
|
||||||
a := 1e6
|
a := 1e6
|
||||||
fmt.Println(a)
|
fmt.Println(a)
|
||||||
arr := []int{1, 2, 3}
|
arr := []int{1, 2, 3}
|
||||||
|
|
|
@ -12,3 +12,11 @@ type person struct{
|
||||||
age int;
|
age int;
|
||||||
work func()
|
work func()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
d := "Debilov";
|
||||||
|
tom := person {name: "Tom", second_name: d, age: 20+2*2};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue