Matt Wette writes:
Hi Matt,
> On 11/12/25 1:51 AM, Janneke Nieuwenhuizen wrote:
>> I found a C99 parse bug
(I realize now that I could have added a "think" somewhere in that sentence:)
[..]
> Hmm. I checked. Your case statement (first one below) does not seem
> to match
> syntax for C99. This might be a gcc bug as it accepts with
> -std=c99. The second
> case statement would pass nyacc.
>
> switch (c)
> {
> case 0:
> int i = 3;
> return 0;
> case 1: {
> int i = 4;
> return 2;
> }
> }
> return 1;
You're right. As you mentioned on IRC; uisng
gcc -std=c99 -pedantic-errors switch.c
gives
--8<---------------cut here---------------start------------->8---
../wip/switch.c: In function ‘main’:
../wip/switch.c:8:7: error: a label can only be part of a statement and a
declaration is not a statement [-Wpedantic]
8 | int i = 3;
| ^~~
--8<---------------cut here---------------end--------------->8---
> I'm not sure how to handle this right now. I could
> kludge for your case with:
>
> --- a/module/nyacc/lang/c99/mach.scm
> +++ b/module/nyacc/lang/c99/mach.scm
> @@ -719,6 +719,7 @@
> (identifier ":" attribute-specifier statement
> ($$ `(labeled-stmt ,$1 ,$4)))
> ("case" constant-expression ":" statement ($$ `(case ,$2 ,$4)))
> + ("case" constant-expression ":" declaration ($$ `(case ,$2 ,$4)))
> ("default" ":" statement ($$ `(default ,$3))))
>
> In the spec `label :' is followed by `statement', not `block-item'.
> See https://slebok.github.io/zoo/c/c99/iso-9899-tc3/extracted/index.html
So I think "we"'re good with NYACC as is, I see no need to "relax" C99's
strictness here, especially as we introduced this problem in the Mes
code.
Thanks!
Greetings,
Janneke
--
Janneke Nieuwenhuizen <[email protected]> | GNU LilyPond https://LilyPond.org
Freelance IT https://www.JoyOfSource.com | https://reasonable-sourcery.coop