patrickhuber / Pliant

MIT License
26 stars 4 forks source link

Bug when processing items where the last symbol is nullable. #44

Closed patrickhuber closed 8 years ago

patrickhuber commented 8 years ago

The aycock horspool algorithm isn't producing the correct parse node when the last symbol in a grammar is nullable.

example 1

grammar

S-> ST | 'a';
B-> ;
T-> 'a' B | 'a';

input

aa

expected tree

(S, 0, 2) = (S, 0, 1) (T, 1, 2);
(S, 0, 1) = ("a", 0, 1);
(T, 1, 2) = ("a", 1, 2)
          | ("a", 1, 2) (B, 2, 2);
(B, 2, 2) = ("", 2, 2);

example 2

grammar

E-> F | FE | ;
F-> a ;

input

aa

expected tree

(E, 0, 2) = (E, 0, 1) (E, 1, 2);
(E, 0, 1) = (F, 0, 1)
          | (F, 0, 1) (E, 1, 1);
(F, 0, 1) = ("a", 0, 1);
(E, 1, 1) = ("", 1, 1);
(E, 1, 2) = (F, 1, 2)
          | (F, 1, 2) (E, 2, 2);
(E, 2, 2) = ("", 1, 1);
(F, 1, 2) = ("a", 1, 2);