BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
586 stars 165 forks source link

Haskell: how to use multiple entrypoints? #374

Closed MurakamiKennzo closed 3 years ago

MurakamiKennzo commented 3 years ago

Hi, I just test like this:

-- M.cf
EInt.   Exp ::= Integer ;
EType. Type ::= "Int" ;

entrypoints Exp, Type ;

complier to Haskell and make:

$ bnfc -d -m M.cf  
$ make

but when I test with the text:

Int

it outputs as:

./test.m

Parse              Failed...

Tokens:
1:1 "Int"
syntax error at line 1, column 1 before `Int'

and when I changed the order of entrypoints:

-- M.cf
EInt.   Exp ::= Integer ;
EType. Type ::= "Int" ;

entrypoints Type, Exp ;

it works well, but the Exp not parsed.

so currently the multiple entrypoints isn't support for Haskell?(but the docs said)

Here are some info:

$ bnfc --version
2.9.2

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.5

$ alex --version
Alex version 3.2.6, (c) 2003 Chris Dornan and Simon Marlow

$ happy --version
Happy Version 1.20.0 Copyright (c) 1993-1996 Andy Gill, Simon Marlow (c) 1997-2005 Simon Marlow
andreasabel commented 3 years ago

The first non-terminal (aka category) is the default entrypoint that is used by the generated test program (Test.hs). However, the generated Par.y also has the other entrypoints.

If you want to parse either Exp or Type without knowing which one you get, you need to define a new category and use this as entry point, e.g.:

EPExp.  EP ::= Exp;
EPType. EP ::= Type;
MurakamiKennzo commented 3 years ago

The first non-terminal (aka category) is the default entrypoint that is used by the generated test program (Test.hs). However, the generated Par.y also has the other entrypoints.

If you want to parse either Exp or Type without knowing which one you get, you need to define a new category and use this as entry point, e.g.:

EPExp.  EP ::= Exp;
EPType. EP ::= Type;

Got it, I find here:

截屏2021-07-30 上午10 44 11

Thanks!