chriswailes / RLTK

The Ruby Language Toolkit
http://chriswailes.github.io/RLTK/
University of Illinois/NCSA Open Source License
453 stars 35 forks source link

bug in evaluating right hand sides #17

Closed eqv closed 11 years ago

eqv commented 11 years ago

There seems to be a problem with regard to nondeterminism in the productions results: parsing AB under S-> (A B? B?)* results in duplicated output. Never mind the global variable, its just to test that the output is indeed generated twice, and not just duplicated.

https://gist.github.com/ranmrdrakono/dfbbe4dbfae599f5b8c7

The output should be (in my opinion) [:body, [[:a, 1]]] but acctually is [:body, [[:a, 1], [:a, 2]]]

chriswailes commented 11 years ago

This is problem is now fixed. Or at least it is for my simple test. Let me know if it doesn't work for you.

On a side note, you will still have a problem with your grammar as things stand now. The production struct_elem -> A NL? NL? is ambiguous, as the grammar doesn't specify if the first or second NL should be getting the value for the NL token when parsing A NL.

Right now the only way to fix the issue would be to create your own nl_question production. I'll be changing the parser generator algorithm soon, though, so that the Kleene operators are greedy (they will prefer to shift then to reduce). This will remove the ambiguity, and cause the first NL? symbol in struct_elem -> A NL? NL? to get the value from A NL deterministically.