debug messages added

ilya
serr 2025-05-13 17:46:21 +03:00
parent 00e45f0c6a
commit 84efc813ad
3 changed files with 34 additions and 23 deletions

View File

@ -54,6 +54,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_]
} }
{LETTER}{LETTER_OR_DIGIT}* { {LETTER}{LETTER_OR_DIGIT}* {
yylval.str = strdup(yytext);
return IDENTIFIER; return IDENTIFIER;
} }

View File

@ -22,15 +22,16 @@ void free_node(char *str) {
} }
%token SHORT_DECLARATION LBRACE RBRACE SEMICOLON ASSIGN LPAREN RPAREN COMMA %token SHORT_DECLARATION LBRACE RBRACE SEMICOLON ASSIGN LPAREN RPAREN COMMA
%token VAR FUNC RETURN IDENTIFIER STRING_LITERAL FLOAT_LITERAL NUMBER %token VAR FUNC RETURN STRING_LITERAL FLOAT_LITERAL NUMBER
%token PLUS MINUS MULT DIV MOD EXP %token PLUS MINUS MULT DIV MOD
%token STRING %token STRING
%token UINT UINT8 UINT16 UINT32 UINT64 %token UINT UINT8 UINT16 UINT32 UINT64
%token INT INT8 INT16 INT32 INT64 %token INT INT8 INT16 INT32 INT64
%token <str> IDENTIFIER
%left PLUS MINUS %left PLUS MINUS
%left MULT DIV MOD %left MULT DIV MOD
%left EXP
%left UMINUS %left UMINUS
%% %%
@ -55,23 +56,23 @@ statements_list:
; ;
expr: expr:
RETURN math_expr { } RETURN math_expr { printf("\033[1;35mRETURN math expr\033[0m\n") }
| RETURN literal { printf("\033[1;35mRETURN literal\033[0m\n") }
| IDENTIFIER ASSIGN math_expr { } | IDENTIFIER ASSIGN math_expr { }
| math_expr { } | math_expr { }
; ;
math_expr: math_expr:
math_expr PLUS math_expr { } math_expr PLUS math_expr { printf("PLUS\n"); }
| math_expr MINUS math_expr { } | math_expr MINUS math_expr { printf("MINUS\n"); }
| math_expr MULT math_expr { } | math_expr MULT math_expr { printf("MULT\n"); }
| math_expr DIV math_expr { } | math_expr DIV math_expr { printf("DIV\n"); }
| math_expr MOD math_expr { } | math_expr MOD math_expr { printf("MOD\n"); }
| math_expr EXP math_expr { } | MINUS math_expr %prec UMINUS { printf("UMINUS\n"); }
| MINUS math_expr %prec UMINUS { } | LPAREN { printf("LPAREN\n"); } math_expr RPAREN { printf("RPAREN\n"); }
| LPAREN math_expr RPAREN { } | NUMBER { printf("NUMBER\n"); }
| NUMBER { } | FLOAT_LITERAL { printf("FLOAT LITERAL\n"); }
| FLOAT_LITERAL { } | IDENTIFIER { printf("IDENTIFIER: %s\n", $1); }
| IDENTIFIER { }
; ;
/* Остальные правила остаются без изменений */ /* Остальные правила остаются без изменений */
@ -104,7 +105,8 @@ literal:
; ;
arg_declaration: arg_declaration:
IDENTIFIER type { } IDENTIFIER type
{ printf("\033[1;35mARG: %s\n\033[0m", $1); }
; ;
arg_list: arg_list:
@ -117,15 +119,18 @@ return_type:
; ;
func_declaration: func_declaration:
FUNC IDENTIFIER LPAREN arg_list RPAREN return_type block { } FUNC IDENTIFIER
{ printf("\033[1;35mHELLO, FUNC: %s\n\033[0m", $2); }
LPAREN arg_list RPAREN return_type block
{ printf("\033[1;35mBY, FUNC: %s\n\n\033[0m", $2); }
; ;
var_declaration: var_declaration:
IDENTIFIER SHORT_DECLARATION math_expr { } IDENTIFIER SHORT_DECLARATION math_expr { printf("\033[1;33mSHORT DECL with math expr: %s\n\033[0m", $1); }
| IDENTIFIER SHORT_DECLARATION literal { } | IDENTIFIER SHORT_DECLARATION literal { printf("\033[1;33mSHORT DECL with literal: %s\n\033[0m", $1); }
| VAR IDENTIFIER type { } | VAR IDENTIFIER type { { printf("\033[1;33mVAR DECL without init value: %s\n\033[0m", $2); } }
| VAR IDENTIFIER type ASSIGN math_expr { } | VAR IDENTIFIER type ASSIGN math_expr { { printf("\033[1;33mVAR DECL with math expr init value: %s\n\033[0m", $2); } }
| VAR IDENTIFIER type ASSIGN literal { } | VAR IDENTIFIER type ASSIGN literal { { printf("\033[1;33mVAR DECL with literal init value: %s\n\033[0m", $2); } }
; ;
%% %%

View File

@ -1,8 +1,13 @@
func test() { func test() {
return "123";
}
return a; func test(a int, b string) {
s := "123njda skjad";
a := 2;
return a + 1;
} }
func main() { func main() {