From 75058ca1e42392e22303257e1c9d40dadcd32711 Mon Sep 17 00:00:00 2001 From: serr Date: Tue, 20 May 2025 23:42:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B4=D0=B5=D0=BA=D0=BB=D0=B0=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyzers/test/test.l | 1 + analyzers/test/test.y | 24 +++++++++++++++++++----- tests/test_interfaces.txt | 6 ++++++ tests/test_methods.txt | 2 +- tests/test_types.txt | 4 ++-- 5 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 tests/test_interfaces.txt diff --git a/analyzers/test/test.l b/analyzers/test/test.l index d6a0154..653093e 100644 --- a/analyzers/test/test.l +++ b/analyzers/test/test.l @@ -73,6 +73,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] "++" { return INC; } "--" { return DEC; } +"interface" { return INTERFACE; } "map" { return MAP; } "struct" { return STRUCT; } "type" { return TYPE; } diff --git a/analyzers/test/test.y b/analyzers/test/test.y index edc9801..bc83f6b 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -25,7 +25,7 @@ void free_node(char *str) { %token VAR FUNC RETURN STRING_LITERAL FLOAT_LITERAL COMPLEX_LITERAL NUMBER PACKAGE IMPORT %token INC DEC PLUS_EQ MINUS_EQ MUL_EQ DIV_EQ MOD_EQ %token AMPERSAND_EQ PIPE_EQ XOR_EQ LSHIFT_EQ RSHIFT_EQ AND_NOT_EQ -%token FOR BREAK CONTINUE ARROW IF ELSE RANGE DEFER GO TYPE STRUCT MAP CHAN +%token FOR BREAK CONTINUE ARROW IF ELSE RANGE DEFER GO TYPE STRUCT MAP CHAN INTERFACE %token CHAN CONST CASE SWITCH MAKE %token PLUS MINUS MULT DIV MOD %token STRING @@ -271,6 +271,9 @@ log_expr: // types +interface_types: + INTERFACE {printf("INTERFACE\n"); } LBRACE interface_declarate_field_list RBRACE + struct_types: STRUCT LBRACE declarate_field_list RBRACE ; @@ -314,6 +317,7 @@ type: | map_types | slice_types | arr_types { } + | interface_types | struct_types { } | func_types { } | string_types { } @@ -462,12 +466,22 @@ map_element: IDENTIFIER LBRACK literal RBRACK | IDENTIFIER LBRACK any_identifier RBRACK +// interface + +interface_field: + IDENTIFIER LPAREN arg_list RPAREN {printf("ret type interface\n");} return_type + +interface_declarate_field_list: + | interface_field SEMICOLON + | interface_declarate_field_list interface_field SEMICOLON + ; + // struct declarate_field_list: - | arg_declaration - | IDENTIFIER - | declarate_field_list SEMICOLON arg_declaration - | declarate_field_list SEMICOLON IDENTIFIER + | arg_declaration SEMICOLON + | IDENTIFIER SEMICOLON + | declarate_field_list arg_declaration SEMICOLON + | declarate_field_list IDENTIFIER SEMICOLON ; field: diff --git a/tests/test_interfaces.txt b/tests/test_interfaces.txt new file mode 100644 index 0000000..fc6bfc1 --- /dev/null +++ b/tests/test_interfaces.txt @@ -0,0 +1,6 @@ +package main; + +type test interface{ + a(a int) (a, b int); + b() (a, b int, string); +}; \ No newline at end of file diff --git a/tests/test_methods.txt b/tests/test_methods.txt index 08f19f0..3bd955e 100644 --- a/tests/test_methods.txt +++ b/tests/test_methods.txt @@ -2,7 +2,7 @@ package main; // Circle - структура, представляющая круг type Circle struct { - Radius float64 + Radius float64; }; // Реализация методов интерфейса Geometry для Circle diff --git a/tests/test_types.txt b/tests/test_types.txt index dc4c93f..7f0a259 100644 --- a/tests/test_types.txt +++ b/tests/test_types.txt @@ -15,12 +15,12 @@ type empty struct{ type person struct{ name string; - age int + age int; }; type person2 struct{ name,second_name string; age int; - person + person; };