From 17dc6b7f8ecab90290f4a08a58b35bdbb65667f5 Mon Sep 17 00:00:00 2001 From: gaomei Date: Sat, 4 Jan 2025 19:40:58 +0800 Subject: [PATCH 1/4] fix 6.4 example --- latex_src/little_languages.tex | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/latex_src/little_languages.tex b/latex_src/little_languages.tex index 39afc37..9b6e633 100644 --- a/latex_src/little_languages.tex +++ b/latex_src/little_languages.tex @@ -675,6 +675,7 @@ \section{逆波兰式计算器} { for (i = 1; i <= NF; i++) if ($i ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)$/) { stack[++top] = $i + continue } else if ($i == "+" && top > 1) { stack[top-1] += stack[top]; top-- } else if ($i == "-" && top > 1) { @@ -690,8 +691,8 @@ \section{逆波兰式计算器} top = 0 next } - if (top == 1) - printf("\t%.8g\n", stack[top--]) + if (top == 1 && i == NF) + printf("\t%.8g\n", stack[top]) else if (top > 1) { printf("error: too many operands\n") top = 0 @@ -730,6 +731,7 @@ \section{逆波兰式计算器} { for (i = 1; i <= NF; i++) if ($i ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)$/) { stack[++top] = $i + continue } else if ($i == "+" && top > 1) { stack[top-1] += stack[top]; top-- } else if ($i == "-" && top > 1) { @@ -763,8 +765,8 @@ \section{逆波兰式计算器} top = 0 next } - if (top == 1 && $NF !~ /\=$/) - printf("\t%.8g\n", stack[top--]) + if (top == 1 && i == NF && $NF !~ /\=$/) + printf("\t%.8g\n", stack[top]) else if (top > 1) { printf("error: too many operands\n") top = 0 From c895398204aed29aea614c4f5d66ea63a6549ece Mon Sep 17 00:00:00 2001 From: gaomei Date: Sat, 4 Jan 2025 19:58:51 +0800 Subject: [PATCH 2/4] fix 6.4 example more line srcfile --- latex_src/little_languages.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/latex_src/little_languages.tex b/latex_src/little_languages.tex index 9b6e633..b05eb9b 100644 --- a/latex_src/little_languages.tex +++ b/latex_src/little_languages.tex @@ -692,7 +692,7 @@ \section{逆波兰式计算器} next } if (top == 1 && i == NF) - printf("\t%.8g\n", stack[top]) + printf("\t%.8g\n", stack[top--]) else if (top > 1) { printf("error: too many operands\n") top = 0 @@ -766,7 +766,7 @@ \section{逆波兰式计算器} next } if (top == 1 && i == NF && $NF !~ /\=$/) - printf("\t%.8g\n", stack[top]) + printf("\t%.8g\n", stack[top--]) else if (top > 1) { printf("error: too many operands\n") top = 0 From 3f48820208482c86673595d6ea2542cc07e93e63 Mon Sep 17 00:00:00 2001 From: gaomei Date: Tue, 7 Jan 2025 20:05:22 +0800 Subject: [PATCH 3/4] fix 6.4 example (delete continue) --- latex_src/little_languages.tex | 2 -- 1 file changed, 2 deletions(-) diff --git a/latex_src/little_languages.tex b/latex_src/little_languages.tex index b05eb9b..9170f5f 100644 --- a/latex_src/little_languages.tex +++ b/latex_src/little_languages.tex @@ -675,7 +675,6 @@ \section{逆波兰式计算器} { for (i = 1; i <= NF; i++) if ($i ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)$/) { stack[++top] = $i - continue } else if ($i == "+" && top > 1) { stack[top-1] += stack[top]; top-- } else if ($i == "-" && top > 1) { @@ -731,7 +730,6 @@ \section{逆波兰式计算器} { for (i = 1; i <= NF; i++) if ($i ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)$/) { stack[++top] = $i - continue } else if ($i == "+" && top > 1) { stack[top-1] += stack[top]; top-- } else if ($i == "-" && top > 1) { From a04c1b57a952280bf4804c6867f232c68c0af20c Mon Sep 17 00:00:00 2001 From: gaomei Date: Tue, 7 Jan 2025 20:08:22 +0800 Subject: [PATCH 4/4] fix 6.4 example --- latex_src/little_languages.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/latex_src/little_languages.tex b/latex_src/little_languages.tex index 9170f5f..291bda1 100644 --- a/latex_src/little_languages.tex +++ b/latex_src/little_languages.tex @@ -729,7 +729,7 @@ \section{逆波兰式计算器} { for (i = 1; i <= NF; i++) if ($i ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)$/) { - stack[++top] = $i + stack[++top] = $i } else if ($i == "+" && top > 1) { stack[top-1] += stack[top]; top-- } else if ($i == "-" && top > 1) {