добавил методы
parent
173943589a
commit
faf37642dc
|
@ -58,6 +58,7 @@ program:
|
|||
;
|
||||
|
||||
statement:
|
||||
| method_declaration
|
||||
| GO func_call SEMICOLON
|
||||
| DEFER func_call SEMICOLON
|
||||
| func_call SEMICOLON
|
||||
|
@ -306,7 +307,9 @@ func_types:
|
|||
FUNC LPAREN arg_list RPAREN return_type
|
||||
|
||||
type:
|
||||
|
||||
int_types { }
|
||||
| IDENTIFIER
|
||||
| chan_types
|
||||
| map_types
|
||||
| slice_types
|
||||
|
@ -391,19 +394,25 @@ slice_types:
|
|||
|
||||
// functions
|
||||
|
||||
func_literal:
|
||||
FUNC
|
||||
{ printf("\033[1;35mHELLO, ANON FUNC\n\033[0m"); }
|
||||
LPAREN arg_list RPAREN return_type block
|
||||
{ printf("\033[1;35mBY, ANON FUNC\n\n\033[0m"); }
|
||||
// Анонимная функция
|
||||
anon_func:
|
||||
FUNC LPAREN arg_list RPAREN return_type block
|
||||
{ printf("\033[1;35mANONYMOUS FUNC\n\033[0m"); }
|
||||
;
|
||||
|
||||
// Литерал функции (если нужно для других правил)
|
||||
func_literal: anon_func;
|
||||
|
||||
// Вызов функции
|
||||
func_call:
|
||||
any_identifier LPAREN math_expr_or_literals_list_or_empty RPAREN
|
||||
| func_literal LPAREN math_expr_or_literals_list_or_empty RPAREN
|
||||
| anon_func LPAREN math_expr_or_literals_list_or_empty RPAREN
|
||||
| anon_func // Позволяет использовать func(){} как значение
|
||||
;
|
||||
|
||||
arg_declaration:
|
||||
identifiers_list type
|
||||
{ printf("\033[1;35mARG DECLARATIONS:\n\033[0m"); }
|
||||
{ printf("\033[1;35mARG DECLARATIONS\n\033[0m"); }
|
||||
;
|
||||
|
||||
arg_list:
|
||||
|
@ -423,7 +432,15 @@ func_declaration:
|
|||
LPAREN arg_list RPAREN return_type block
|
||||
{ printf("\033[1;35mBY, FUNC: %s\n\n\033[0m", $2); }
|
||||
;
|
||||
//
|
||||
|
||||
// Объявление метода
|
||||
method_declaration:
|
||||
FUNC LPAREN IDENTIFIER type RPAREN IDENTIFIER
|
||||
{ printf("\033[1;35mMETHOD DECL: %s\n\033[0m", $6); }
|
||||
LPAREN arg_list RPAREN return_type block
|
||||
{ printf("\033[1;35mEND METHOD\n\033[0m"); }
|
||||
;
|
||||
|
||||
|
||||
// map
|
||||
map_field:
|
||||
|
|
|
@ -37,8 +37,12 @@ func iife(work int) {
|
|||
|
||||
|
||||
for i := 1; i < 3; i++ {
|
||||
|
||||
go func(a int) {
|
||||
fmt.Println(123);
|
||||
}();
|
||||
|
||||
func(){}();
|
||||
func(){fmt.Println(123);}();
|
||||
|
||||
go func(a, b string) {
|
||||
fmt.Println("Message:", a + b);
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package main;
|
||||
|
||||
// Circle - структура, представляющая круг
|
||||
type Circle struct {
|
||||
Radius float64
|
||||
};
|
||||
|
||||
// Реализация методов интерфейса Geometry для Circle
|
||||
func (c Circle) Area() float64 {
|
||||
return math.Pi * c.Radius * c.Radius;
|
||||
}
|
||||
|
||||
func (c Circle) Perimeter() float64 {
|
||||
return 2 * math.Pi * c.Radius;
|
||||
}
|
||||
|
||||
func (c Circle) Name() string {
|
||||
return "Круг";
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue