добавил возможность опрделения типов

master2
serr 2025-05-18 20:30:18 +03:00
parent cfdd475fc1
commit 51a96ccd5f
5 changed files with 32 additions and 14 deletions

View File

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

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
%token FOR BREAK CONTINUE ARROW IF ELSE RANGE DEFER GO TYPE
%token CHAN CONST CASE SWITCH
%token PLUS MINUS MULT DIV MOD
%token STRING
@ -68,6 +68,8 @@ statement:
{ printf("\033[1;33mSTATEMENT: variable multiple declaration\033[0m\n"); }
| func_declaration
{ printf("\033[1;33mSTATEMENT: function declaration\033[0m\n"); }
| type_delcaration SEMICOLON
{ printf("\033[1;33mSTATEMENT: type declaration\033[0m\n"); }
| cicle
{ printf("\033[1;33mSTATEMENT: cicle\033[0m\n"); }
| condition
@ -93,7 +95,7 @@ statements_list:
;
identifiers_list:
IDENTIFIER { }
| IDENTIFIER { }
| identifiers_list COMMA IDENTIFIER { }
math_expr_or_literals_list:
@ -278,7 +280,7 @@ string_types:
;
func_types:
FUNC LPAREN RPAREN return_type
FUNC LPAREN arg_list RPAREN return_type
type:
int_types { }
@ -372,6 +374,10 @@ var_declaration:
| VAR IDENTIFIER type ASSIGN literal { { printf("\033[1;33mVAR DECL with literal init value: %s\n\033[0m", $2); } }
;
// type decl
type_delcaration:
TYPE IDENTIFIER type { { printf("\033[1;33mTYPE DECL\n\033[0m"); } }
%%
//

View File

@ -5,6 +5,10 @@ import (
"log"
)
func test(int, int) {
}
func ujas() (func() func() func() int, int, string) {
return func() func() func() int {
return func() func() int {

View File

@ -10,6 +10,7 @@ func server(a int) {
func iife(work int) {
for i := 1; i < 3; i++ {
func(){}();
func(){fmt.Println(123);}();
@ -22,6 +23,7 @@ func iife(work int) {
go log.Println("work failed:", err);
}
}();
}
}
func ujas() (func() func() func() int, int, string) {

5
tests/test_types.txt Normal file
View File

@ -0,0 +1,5 @@
package main;
import "fmt";
type mile uint;
type BinaryOp func(int, int) int;