From be95ad05e3f4343600268cdc9575afcdef278193 Mon Sep 17 00:00:00 2001 From: serr Date: Sun, 18 May 2025 18:59:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D1=83=D1=8E=20=D1=8D?= =?UTF-8?q?=D0=BA=D1=81=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=86=D0=B8=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20=D1=87=D0=B0=D1=81=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BA=20=D1=87=D0=B8=D1=81=D0=BB=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyzers/test/test.l | 21 +++++++++++++-------- analyzers/test/test.y | 17 +++++++++++++++-- tests/main.go | 3 ++- tests/test.txt | 23 ++++++++++++++++++++++- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/analyzers/test/test.l b/analyzers/test/test.l index 5c6e542..841a065 100644 --- a/analyzers/test/test.l +++ b/analyzers/test/test.l @@ -13,6 +13,7 @@ void yyerror(const char *s) { %} +EXPONENT [eE][+-]?{DIGIT}+ DIGIT [0-9] LETTER [a-zA-Z_] LETTER_OR_DIGIT [a-zA-Z0-9_] @@ -129,22 +130,26 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] } } -{DIGIT}+\.{DIGIT}*i { /* Комплексные числа: 123.456i */ +{DIGIT}+\.{DIGIT}*{EXPONENT}?i { yylval.str = strdup(yytext); - return COMPLEX_LITERAL; + return COMPLEX_LITERAL; } -{DIGIT}+i { /* Комплексные числа: 123i */ +{DIGIT}+{EXPONENT}?i { yylval.str = strdup(yytext); - return COMPLEX_LITERAL; + return COMPLEX_LITERAL; } -{DIGIT}+\.{DIGIT}+ { /* Обычные float: 123.456 */ - return FLOAT_LITERAL; +{DIGIT}+\.{DIGIT}*{EXPONENT}? { + return FLOAT_LITERAL; } -{DIGIT}+ { /* Целые числа */ - return NUMBER; +{DIGIT}+{EXPONENT} { + return FLOAT_LITERAL; +} + +{DIGIT}+ { + return NUMBER; } [ \t\r]+ ; // Пропускаем пробелы и табы diff --git a/analyzers/test/test.y b/analyzers/test/test.y index c553cc7..6540b32 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -191,12 +191,25 @@ continue_statement: expr: RETURN math_expr_or_literals_list_or_empty { 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 { printf("PLUS\n"); } + IDENTIFIER ASSIGN math_expr { } + | IDENTIFIER PLUS_EQ math_expr + | IDENTIFIER MINUS_EQ math_expr + | IDENTIFIER MUL_EQ math_expr + | IDENTIFIER DIV_EQ math_expr + + | IDENTIFIER MOD_EQ math_expr + | IDENTIFIER AMPERSAND_EQ math_expr + | IDENTIFIER PIPE_EQ math_expr + | IDENTIFIER XOR_EQ math_expr + | IDENTIFIER LSHIFT_EQ math_expr + | IDENTIFIER RSHIFT_EQ math_expr + | IDENTIFIER AND_NOT_EQ math_expr + + | 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"); } diff --git a/tests/main.go b/tests/main.go index 58bff87..f31a178 100644 --- a/tests/main.go +++ b/tests/main.go @@ -3,7 +3,8 @@ package main import "fmt" func main() { - + a := 1e6 + fmt.Println(a) arr := []int{1, 2, 3} for idx, val := range arr { fmt.Println(idx, val) diff --git a/tests/test.txt b/tests/test.txt index 935c417..c0e7812 100644 --- a/tests/test.txt +++ b/tests/test.txt @@ -5,7 +5,24 @@ import ( "log"; ) + +// A toy implementation of cube root using Newton's method. +func CubeRoot(x float64) float64 { + z := x/3; // Arbitrary initial value + for i := 0; i < 1e6; i++ { + prevz := z; + z -= (z*z*z-x) / (3*z*z); + if veryClose(z, prevz) { + return z; + } + } + // A million iterations has not converged; something is wrong. + panic(fmt.Sprintf("CubeRoot(%g) did not converge", x)); +} + + func test() { + z -= (z*z*z-x) / (3*z*z); return "123"; } @@ -18,7 +35,11 @@ func test(a int, b string) { func main() { var a int; - a = 2+2*2-(1+10)+213i*2 - 2.123i; + var c complex128 = 555.12i+1.123i; + + a := 123+123e45 + 123.456 +123.456e-78+123i+123.456e10i; + + a = 2+2*2-(1+10)+213i*2 - 2.123i - c; a = a + 1; a = a; } \ No newline at end of file