добавил возможность опрделения типов
parent
cfdd475fc1
commit
51a96ccd5f
|
@ -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; }
|
||||||
|
|
|
@ -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"); } }
|
||||||
|
|
||||||
%%
|
%%
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -9,19 +9,21 @@ func server(a int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func iife(work int) {
|
func iife(work int) {
|
||||||
|
|
||||||
|
for i := 1; i < 3; i++ {
|
||||||
|
func(){}();
|
||||||
|
func(){fmt.Println(123);}();
|
||||||
|
|
||||||
func(){}();
|
go func(a, b string) {
|
||||||
func(){fmt.Println(123);}();
|
fmt.Println("Message:", a + b);
|
||||||
|
}("Hello", ", world!");
|
||||||
|
|
||||||
go func(a, b string) {
|
defer func() {
|
||||||
fmt.Println("Message:", a + b);
|
if err := recover(); err != nil {
|
||||||
}("Hello", ", world!");
|
go log.Println("work failed:", err);
|
||||||
|
}
|
||||||
defer func() {
|
}();
|
||||||
if err := recover(); err != nil {
|
}
|
||||||
go log.Println("work failed:", err);
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ujas() (func() func() func() int, int, string) {
|
func ujas() (func() func() func() int, int, string) {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package main;
|
||||||
|
import "fmt";
|
||||||
|
|
||||||
|
type mile uint;
|
||||||
|
type BinaryOp func(int, int) int;
|
Loading…
Reference in New Issue