commit bda3c885596c445a3f181c3935eabd953b455486
parent 4e3d54e231f17d851ee58031d8e2becf75b81302
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Sun, 23 Nov 2025 12:31:30 +0100
bc: Fix comment parsing
The function comment was misparsing comments, because it ate always
the character after a *, invalidating sequences like **/. Also, as it
didn't count new line characters error messages were misleading.
Diffstat:
| M | bc.y | | | 15 | +++++++++++---- |
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/bc.y b/bc.y
@@ -587,10 +587,17 @@ operand(int ch)
static void
comment(void)
{
- do {
- while (getchar() != '*')
- ;
- } while (getchar() != '/');
+ int c;
+
+ for (;;) {
+ while ((c = getchar()) != '*') {
+ if (c == '\n')
+ lineno++;
+ }
+ if ((c = getchar()) == '/')
+ break;
+ ungetc(c, stdin);
+ }
}
static int