Intro example leads to errors

1 view
Skip to first unread message

Martin Erwig

unread,
Aug 17, 2025, 9:05:49 PMAug 17
to BNFC Developers and Users
Hi folks,

When I try to run the introductory example Calc.cf with the latest version of BNFC (2.9.6.1), I get a number of errors from ghc (9.12.2). I have attached the output below. Any ideas of what I'm doing wrong here, or any suggestions for what I could try?

Thanks!
Martin

---

> bnfc --haskell -d -m Calc.cf  &&  make
8 rules accepted

Use Alex 3 to compile Calc/Lex.x.
writing new file ./Calc/Abs.hs
writing new file ./Calc/Print.hs
writing new file ./Calc/Lex.x
writing new file ./Calc/Par.y
writing new file ./Calc/Test.hs
writing new file ./Calc/ErrM.hs
writing new file ./Calc/Skel.hs
writing new file ./Calc/Doc.txt
writing new file ./Makefile
alex --ghc Calc/Lex.x
happy --array --info --ghc --coerce Calc/Par.y
ghc  Calc/Test
[1 of 7] Compiling Calc.Abs         ( Calc/Abs.hs, Calc/Abs.o )
[2 of 7] Compiling Calc.Lex         ( Calc/Lex.hs, Calc/Lex.o )
Calc/Lex.hs:384:50: error: [GHC-83865]
    • Couldn't match expected type ‘Int16#’ with actual type ‘Int#’
    • In the fifth argument of ‘alex_scan_tkn’, namely ‘sc’
      In the expression:
        alex_scan_tkn user__ input__ 0# input__ sc AlexNone
      In the expression:
        case alex_scan_tkn user__ input__ 0# input__ sc AlexNone of
          (AlexNone, input__')
            -> case alexGetByte input__ of
                 Nothing -> AlexEOF
                 Just _ -> AlexError input__'
          (AlexLastSkip input__'' len, _) -> AlexSkip input__'' len
          (AlexLastAcc k input__''' len, _)
            -> AlexToken input__''' len (alex_actions ! k)
    |
384 |   = case alex_scan_tkn user__ input__ 0# input__ sc AlexNone of
    |                                                  ^^

Calc/Lex.hs:414:1: error: [GHC-83865]
    Couldn't match type ‘Int#’ with ‘Int16#’
    Expected: t1
              -> t2
              -> Int#
              -> AlexInput
              -> Int16#
              -> AlexLastAcc
              -> (AlexLastAcc, AlexInput)
      Actual: t1
              -> t2
              -> Int#
              -> AlexInput
              -> Int#
              -> AlexLastAcc
              -> (AlexLastAcc, AlexInput)
    |
414 | alex_scan_tkn user__ orig_input len input__ s last_acc =
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Calc/Lex.hs:429:27: error: [GHC-83865]
    • Couldn't match expected type ‘Int#’ with actual type ‘Int32#’
    • In the first argument of ‘(+#)’, namely ‘base’
      In the expression: base +# ord_c
      In an equation for ‘offset’: offset = (base +# ord_c)
    |
429 |                 offset = (base +# ord_c)
    |                           ^^^^

Calc/Lex.hs:432:73: error: [GHC-83865]
    • Couldn't match expected type ‘Int#’ with actual type ‘Int16#’
    • In the first argument of ‘(==#)’, namely ‘check’
      In the first argument of ‘tagToEnum#’, namely ‘(check ==# ord_c)’
      In the second argument of ‘(&&)’, namely
        ‘(tagToEnum# (check ==# ord_c))’
    |
432 |                 new_s = if GTE(offset,0#) && EQ(check,ord_c)
    |                                                                         ^^^^^

Calc/Lex.hs:437:13: error: [GHC-83865]
    • Couldn't match expected type ‘Int16#’ with actual type ‘Int#’
    • In the pattern: -1#
      In a case alternative: -1# -> (new_acc, input__)
      In the expression:
        case new_s of
          -1# -> (new_acc, input__)
          _ -> alex_scan_tkn
                 user__ orig_input
                 (if c < 0x80 || c >= 0xC0 then (len +# 1#) else len) new_input
                 new_s new_acc
    |
437 |             -1# -> (new_acc, input__)
    |             ^^^

[4 of 7] Compiling Calc.Print       ( Calc/Print.hs, Calc/Print.o )
[5 of 7] Compiling Calc.Skel        ( Calc/Skel.hs, Calc/Skel.o )
make: *** [Calc/Test] Error 1

Reply all
Reply to author
Forward
0 new messages