mdaines / grammophone

A tool for analyzing and transforming context-free grammars.
https://mdaines.github.io/grammophone
MIT License
205 stars 23 forks source link

The 'Transform' tab breaks on the following simple example grammar #10

Closed Qqwy closed 3 years ago

Qqwy commented 3 years ago
S -> A a A b.
S -> B b B a.
A -> .
B -> .

The Analyze tab works correctly, but the Transform tab does not show any results, and in the devtools we can see:

Uncaught TypeError: grammar.productions[group[0]] is undefined
    epsilonSeparate https://mdaines.github.io/grammophone/assets/application.js:2409
    "transformations.epsilonSeparate" https://mdaines.github.io/grammophone/assets/application.js:2497
    calculate https://mdaines.github.io/grammophone/assets/application.js:3018
    transformations https://mdaines.github.io/grammophone/assets/application.js:2571
    calculate https://mdaines.github.io/grammophone/assets/application.js:3018
    getTransformations https://mdaines.github.io/grammophone/assets/application.js:3932
    reload https://mdaines.github.io/grammophone/assets/application.js:3847
    reload https://mdaines.github.io/grammophone/assets/application.js:3907
    transform https://mdaines.github.io/grammophone/assets/application.js:4260
    ModeController https://mdaines.github.io/grammophone/assets/application.js:4004
    bind https://mdaines.github.io/grammophone/assets/application.js:4068
    proxyfn https://mdaines.github.io/grammophone/assets/zepto.js:660
application.js:2409:18
mdaines commented 3 years ago

It looks like the epsilon-separate transformation doesn't handle the case when a nullable nonterminal has only one production. This is a reduced example:

A -> .

I don't think it makes sense to apply epsilon separation in this case, because the new symbol A* would have no productions:

x -> b_1 | ... | b_n | .
==>
x -> x* | .
x* -> b_1 | ... | b_n .

A -> .
==>
A -> A* | .
A* -> ?

5265500 should address this.

mdaines commented 3 years ago

Also, thank you for reporting this!