From 84efc813adc947a40efb5ce10c1fd3d092e701d9 Mon Sep 17 00:00:00 2001 From: serr Date: Tue, 13 May 2025 17:46:21 +0300 Subject: [PATCH] debug messages added --- analyzers/test/test.l | 1 + analyzers/test/test.y | 49 ++++++++++++++++++++++++------------------- tests/test_math.txt | 7 ++++++- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/analyzers/test/test.l b/analyzers/test/test.l index 20be97b..23a9b66 100644 --- a/analyzers/test/test.l +++ b/analyzers/test/test.l @@ -54,6 +54,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] } {LETTER}{LETTER_OR_DIGIT}* { + yylval.str = strdup(yytext); return IDENTIFIER; } diff --git a/analyzers/test/test.y b/analyzers/test/test.y index eac2e85..e2f01ed 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -22,15 +22,16 @@ void free_node(char *str) { } %token SHORT_DECLARATION LBRACE RBRACE SEMICOLON ASSIGN LPAREN RPAREN COMMA -%token VAR FUNC RETURN IDENTIFIER STRING_LITERAL FLOAT_LITERAL NUMBER -%token PLUS MINUS MULT DIV MOD EXP +%token VAR FUNC RETURN STRING_LITERAL FLOAT_LITERAL NUMBER +%token PLUS MINUS MULT DIV MOD %token STRING %token UINT UINT8 UINT16 UINT32 UINT64 %token INT INT8 INT16 INT32 INT64 +%token IDENTIFIER + %left PLUS MINUS %left MULT DIV MOD -%left EXP %left UMINUS %% @@ -55,23 +56,23 @@ statements_list: ; 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 { } | math_expr { } ; math_expr: - math_expr PLUS math_expr { } - | math_expr MINUS math_expr { } - | math_expr MULT math_expr { } - | math_expr DIV math_expr { } - | math_expr MOD math_expr { } - | math_expr EXP math_expr { } - | MINUS math_expr %prec UMINUS { } - | LPAREN math_expr RPAREN { } - | NUMBER { } - | FLOAT_LITERAL { } - | IDENTIFIER { } + math_expr PLUS math_expr { printf("PLUS\n"); } + | math_expr MINUS math_expr { printf("MINUS\n"); } + | math_expr MULT math_expr { printf("MULT\n"); } + | math_expr DIV math_expr { printf("DIV\n"); } + | math_expr MOD math_expr { printf("MOD\n"); } + | MINUS math_expr %prec UMINUS { printf("UMINUS\n"); } + | LPAREN { printf("LPAREN\n"); } math_expr RPAREN { printf("RPAREN\n"); } + | NUMBER { printf("NUMBER\n"); } + | FLOAT_LITERAL { printf("FLOAT LITERAL\n"); } + | IDENTIFIER { printf("IDENTIFIER: %s\n", $1); } ; /* Остальные правила остаются без изменений */ @@ -104,7 +105,8 @@ literal: ; arg_declaration: - IDENTIFIER type { } + IDENTIFIER type + { printf("\033[1;35mARG: %s\n\033[0m", $1); } ; arg_list: @@ -117,15 +119,18 @@ return_type: ; 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: - IDENTIFIER SHORT_DECLARATION math_expr { } - | IDENTIFIER SHORT_DECLARATION literal { } - | VAR IDENTIFIER type { } - | VAR IDENTIFIER type ASSIGN math_expr { } - | VAR IDENTIFIER type ASSIGN literal { } + IDENTIFIER SHORT_DECLARATION math_expr { printf("\033[1;33mSHORT DECL with math expr: %s\n\033[0m", $1); } + | IDENTIFIER SHORT_DECLARATION literal { printf("\033[1;33mSHORT DECL with literal: %s\n\033[0m", $1); } + | VAR IDENTIFIER type { { printf("\033[1;33mVAR DECL without init value: %s\n\033[0m", $2); } } + | 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 { { printf("\033[1;33mVAR DECL with literal init value: %s\n\033[0m", $2); } } ; %% diff --git a/tests/test_math.txt b/tests/test_math.txt index 7a5fe84..68253f1 100644 --- a/tests/test_math.txt +++ b/tests/test_math.txt @@ -1,8 +1,13 @@ func test() { + return "123"; +} - return a; +func test(a int, b string) { + s := "123njda skjad"; + a := 2; + return a + 1; } func main() {