On 11/12/25 1:51 AM, Janneke Nieuwenhuizen wrote:
I found a C99 parse bug after we refactored Mes' src/display.c:
declacing a variable as first statement of a `case' statement gives

--8<---------------cut here---------------start------------->8---
$ MES=guile ./pre-inst-env mescc switch.c
switch.c:8: parse failed at state 623, on input "int"
--8<---------------cut here---------------end--------------->8---

See attached file.  As Mes currently supports NYACC >= 1.00.2 (we should
probably raise that requirement, for the new bootstrap we use latest
greatest anyway to be able compile latest tcc), I've moved the
statements inside case into a block; so there's no urgency at all from
our side.

Greetings,
Janneke


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;


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

Matt


Reply via email to