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

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 INC; }
"--" { return DEC; } "--" { return DEC; }
"type" { return TYPE; }
"go" { return GO; } "go" { return GO; }
"defer" { return DEFER; } "defer" { return DEFER; }
"range" { return RANGE; } "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 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 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 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 CHAN CONST CASE SWITCH
%token PLUS MINUS MULT DIV MOD %token PLUS MINUS MULT DIV MOD
%token STRING %token STRING
@ -68,6 +68,8 @@ statement:
{ printf("\033[1;33mSTATEMENT: variable multiple declaration\033[0m\n"); } { printf("\033[1;33mSTATEMENT: variable multiple declaration\033[0m\n"); }
| func_declaration | func_declaration
{ printf("\033[1;33mSTATEMENT: function declaration\033[0m\n"); } { printf("\033[1;33mSTATEMENT: function declaration\033[0m\n"); }
| type_delcaration SEMICOLON
{ printf("\033[1;33mSTATEMENT: type declaration\033[0m\n"); }
| cicle | cicle
{ printf("\033[1;33mSTATEMENT: cicle\033[0m\n"); } { printf("\033[1;33mSTATEMENT: cicle\033[0m\n"); }
| condition | condition
@ -93,7 +95,7 @@ statements_list:
; ;
identifiers_list: identifiers_list:
IDENTIFIER { } | IDENTIFIER { }
| identifiers_list COMMA IDENTIFIER { } | identifiers_list COMMA IDENTIFIER { }
math_expr_or_literals_list: math_expr_or_literals_list:
@ -278,7 +280,7 @@ string_types:
; ;
func_types: func_types:
FUNC LPAREN RPAREN return_type FUNC LPAREN arg_list RPAREN return_type
type: type:
int_types { } 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); } } | 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" "log"
) )
func test(int, int) {
}
func ujas() (func() func() func() int, int, string) { func ujas() (func() func() func() int, int, string) {
return func() func() func() int { return func() func() func() int {
return func() func() int { return func() func() int {

View File

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

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;