From 204a2badd62268067ccc5388614960c272d5d4ea Mon Sep 17 00:00:00 2001 From: serr Date: Sun, 18 May 2025 18:24:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=82=D0=B8=D0=BF=20bool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyzers/test/test.l | 6 ++++-- analyzers/test/test.y | 7 ++++++- tests/test_func_calls.txt | 4 ++++ tests/test_if.txt | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/analyzers/test/test.l b/analyzers/test/test.l index 065f018..489d85f 100644 --- a/analyzers/test/test.l +++ b/analyzers/test/test.l @@ -22,6 +22,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] "string" { return STRING; } +"bool" { return BOOL; } "uint" { return UINT; } "uint8" { return UINT8; } "uint16" { return UINT16; } @@ -39,12 +40,13 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] "float32" { return FLOAT32; } "float64" { return FLOAT64; } "uintptr" { return UINT_PTR; } -"true" { return BOOL_LITERAL; } -"false" { return BOOL_LITERAL; } "if" { return IF; } "else" { return ELSE; } "<-" { return ARROW; } +"true" { return BOOL_LITERAL; } +"false" { return BOOL_LITERAL; } + "==" { return EQ; } "&&" { return AND; } "||" { return OR; } diff --git a/analyzers/test/test.y b/analyzers/test/test.y index e420d6e..07f4314 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -31,7 +31,7 @@ void free_node(char *str) { %token STRING %token UINT UINT8 UINT16 UINT32 UINT64 UINT_PTR %token INT INT8 INT16 INT32 INT64 -%token RUNE BYTE BOOL_LITERAL +%token RUNE BYTE BOOL_LITERAL BOOL %token FLOAT32 FLOAT64 %token COMPLEX64 COMPLEX128 %token IDENTIFIER WITH_DOT_IDENTIFIER @@ -228,6 +228,10 @@ log_expr: // // types + +bool_types: + BOOL + int_types: UINT { } | UINT8 { } @@ -258,6 +262,7 @@ type: | string_types { } | float_types { } | complex_types { } + | bool_types { } ; // diff --git a/tests/test_func_calls.txt b/tests/test_func_calls.txt index ef51096..f14da8c 100644 --- a/tests/test_func_calls.txt +++ b/tests/test_func_calls.txt @@ -8,6 +8,10 @@ func test(a int) int { return a; } +func isValid() bool { + return true; +} + func main() { a := test(1); // вызов функции обычной fmt.Println(test(test(1)*2+3 - a)); // вызов функции из fmt diff --git a/tests/test_if.txt b/tests/test_if.txt index ecfbb6b..1466ca0 100644 --- a/tests/test_if.txt +++ b/tests/test_if.txt @@ -49,7 +49,7 @@ func isValid() bool { } func shouldReturn() bool { - return false + return false; } if a, b := 1, 2; a < b && b < 3 { }