multiple declaration для переменных пользовательских типов добавил
parent
7d657b204d
commit
aafcb40f9b
|
@ -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); } }
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"; // декларация нескольких переменных (строковые литералы)
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Reference in New Issue