Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow or check overwriting of build-in token types #197

Open
andreasabel opened this issue Nov 24, 2016 · 5 comments
Open

Allow or check overwriting of build-in token types #197

andreasabel opened this issue Nov 24, 2016 · 5 comments
Labels
enhancement LBNF Concerning the LBNF syntax and its checking lexer Concerning the generated lexer

Comments

@andreasabel
Copy link
Member

BNFC passes this

EId. Expr ::= Ident;
EAdd. Expr ::= Expr "+" Expr;

token Ident (letter (letter)*);

but it fails in the Haskell backend:

happy -gca Ident/Par.y
Ident/Par.y: 25: multiple use of 'L_ident'
Ident/Par.y: 27: multiple use of 'L_ident'
Ident/Par.y: multiple use of 'L_ident'
Ident/Par.y: multiple use of 'L_ident'

Ideally, token Ident ... should overwrite the built-in definition of Ident.
At least, there should be an error message from bnfc.

@andreasabel
Copy link
Member Author

I started to work on this towards allowing the overwrite, but I realized I will have to modify every single backend for this. :(
(I expected the implementation of bnfc to be a bit more modular...)

@gdetrez
Copy link
Contributor

gdetrez commented Nov 25, 2016

Yes. Right now each backend adds its own hard-coded definition for the built-in token types.

I think the right way to fix this is to add the built-in token categories to the CF object that is then passed to the backend. Once the lbnf file has been parsed, we should add the built-in token types that are 1) used in the grammar and 2) not defined by the user.

if you look in src/BNFC/Lexing.ht the regular expressions for each of the built-in tokens are defined there. What's left is to add them to the cf value in GetCF and remove the hard coded values from the different backends (but GetCF being a bit of a mess that might not be the easiest job 😕)

@gdetrez
Copy link
Contributor

gdetrez commented Nov 25, 2016

The good thing is that now that there is a big regression test suite, changing all the backends is a bit less scarry than it used to be...

I assigned this issue to you since you said you started working on this. 👍

@andreasabel
Copy link
Member Author

Ok, I will have a go at it. I already changed Lexing.hs, but then I have to do the refactoring so that this change is picked up by the backends.

@andreasabel
Copy link
Member Author

This issue gets more weight by problems such as #302 (comment) .

@andreasabel andreasabel removed their assignment Nov 2, 2020
@andreasabel andreasabel added enhancement LBNF Concerning the LBNF syntax and its checking lexer Concerning the generated lexer labels Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement LBNF Concerning the LBNF syntax and its checking lexer Concerning the generated lexer
Projects
None yet
Development

No branches or pull requests

2 participants