6

I'm using Bison to generate a parser. I've got one shift/reduce conflict where I really need Bison to use GLR rather than LALR to deal with it. But I've passed the %glr-parser directive and the source file still states that it's a LALR parser. I even found a "glr.cc" skeleton which suggests that it is a GLR C++ parser and using it by %skeleton "glr.cc" didn't change the output. Does Bison not ship all algorithms for all it's target languages?

Puppy
  • 144,682
  • 38
  • 256
  • 465

3 Answers3

2

You just need %glr-parser to get a GLR parser. Note that GLR parsers may STILL have conflicts (shift/reduce or reduce/reduce), its just that the generated parser will try both alternatives and unify the result.

If you want to shut up the messages about the conflicts, you can use %expect and %expect-rr. Hoever, just blindly using a GLR parser where you don't understand what all the conflicts are is dangerous -- the resulting parser might take exponentially long to parse some inputs if you're not careful, or might give you ambiguity errors at runtime.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • This doesn't really answer the question- I said I attempted `%glr-parser` – Puppy Dec 15 '11 at 23:53
  • @DeadMG: then you got a GLR parser. Its just that GLR parsers have the same shift/reduce and reduce/reduce conflicts as LALR parsers, they just deal with them in a different way. – Chris Dodd Dec 16 '11 at 00:11
  • I didn't say I didn't have one because it still reported conflicts, I said I still had one because the source file's comments still stated so. – Puppy Dec 16 '11 at 01:04
  • Then you might have outdated generated files. Details on what bison's output is and what are the comments that are confusing might really help people see the problem. – Mihai Timar Oct 02 '12 at 11:21
1

I don't know what you mean by "%skeleton "glr.cc" didn't change the output", because it does! Are you sure you really regenerated the output? If you did, please provide more details.

$ echo "%% exp: '0'" > /tmp/f.y
$ bison -S lalr1.cc /tmp/f.y -o f1.cc
$ bison -S glr.cc /tmp/f.y -o f2.cc
$ ls -l f1.cc f2.cc
-rw-r--r--  1 akim  wheel  28373 30 oct 09:29 f1.cc
-rw-r--r--  1 akim  wheel  82767 30 oct 09:29 f2.cc
akim
  • 8,255
  • 3
  • 44
  • 60
0

I've got the same problem. The things I've learned — Bison return 1 if fail to generate new output. The question: why? Because I have disabled C++ Variants (%define api.value.type variant), that is not supported by GLR in Bison, but forget about %define api.token.constructor. And Bison with no promt just breaks.

Good luck with troubleshooting.

faserg1
  • 11
  • 4