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

YACC nothing #7

Open
HarryAnkers opened this issue Feb 13, 2018 · 2 comments
Open

YACC nothing #7

HarryAnkers opened this issue Feb 13, 2018 · 2 comments

Comments

@HarryAnkers
Copy link

is there a way for you to have an option of matching a nothing case in yacc.
for example:
A : B C B
C : SOMETHING
|

Or would I have to do
A : B C B
| B B
C : SOMETHING

@fyquah
Copy link
Contributor

fyquah commented Feb 15, 2018

What you need might be empty rules

I found out about that by googling "Empty sequence" on google, which yields me this stackoverflow post.

@m8pple
Copy link
Contributor

m8pple commented Feb 22, 2018

(I responded to this via email on the 13th, but it doesn't seem to have shown up here.
Usually GH reflects them back up as issues if you respond.)


In bison there is a special token called %epsilon, which can be used
to explicitly mark something as empty-by-intent:

https://www.gnu.org/software/bison/manual/html_node/Empty-Rules.html

C : SOMETHING
| %empty

There is then some nice stuff which will warn you if you declare a production empty, but it isn't.

Doesn't work in classic yacc though, or older versions of bison.
However, you can define a symbol called epsilon:

epsilon : /* I am empty */

then use it in your grammar:

C : SOMETHING
| epsilon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants