добавил struct type

master2
serr 2025-05-18 20:46:00 +03:00
parent 51a96ccd5f
commit 4145259d12
4 changed files with 32 additions and 2 deletions

View File

@ -72,6 +72,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_]
"++" { return INC; }
"--" { return DEC; }
"struct" { return STRUCT; }
"type" { return TYPE; }
"go" { return GO; }
"defer" { return DEFER; }

View File

@ -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
%token FOR BREAK CONTINUE ARROW IF ELSE RANGE DEFER GO TYPE STRUCT
%token CHAN CONST CASE SWITCH
%token PLUS MINUS MULT DIV MOD
%token STRING
@ -251,6 +251,10 @@ log_expr:
// types
struct_types:
STRUCT LBRACE field_list RBRACE
;
bool_types:
BOOL
@ -284,6 +288,7 @@ func_types:
type:
int_types { }
| struct_types { }
| func_types { }
| string_types { }
| float_types { }
@ -364,6 +369,13 @@ func_declaration:
;
//
// struct
field_list:
| arg_declaration
| field_list SEMICOLON arg_declaration
;
//
// vars decl
var_multiple_short_declaration:
identifiers_list SHORT_DECLARATION math_expr_or_literals_list

View File

@ -5,6 +5,14 @@ import (
"log"
)
type person struct {
name, second_name string
age int
}
type epmty struct {
}
func test(int, int) {
}

View File

@ -3,3 +3,12 @@ import "fmt";
type mile uint;
type BinaryOp func(int, int) int;
type empty struct{
};
type person struct{
name, second_name string;
age int;
work func()
};