Skip to content

Left-recursive grammar is not accepted? #7

Description

@gimite

Looks like this package doesn't accept left-recursive grammar. Is it expected? I was wondering because I heard that Earley parser accepts arbitrary context-free language. It looks it accepts right-recursive grammar, though.

parse_test.js:

const {Grammar} = require('probabilistic-earley-parser');

const NP = 'NP';
const N = 'N';
const foo = (token) => !!token.match(/foo/i);
const and = (token) => !!token.match(/and/i);
const grammar = Grammar.builder('test')
  .addNewRule(1.0, NP, [NP, and, N])
  .addNewRule(1.0, NP, [N])
  .addNewRule(1.0, N, [foo])
  .build();
$ node parse_test.js
./node_modules/probabilistic-earley-parser/grammar/left-corner.js:42
                throw new Error("Matrix was not invertable");
                ^

Error: Matrix was not invertable
    at invert (./node_modules/probabilistic-earley-parser/grammar/left-corner.js:42:23)
    at Object.getReflexiveTransitiveClosure (./node_modules/probabilistic-earley-parser/grammar/left-corner.js:113:17)
    at new Grammar (./node_modules/probabilistic-earley-parser/grammar/grammar.js:45:46)
    at GrammarBuilder.build (./node_modules/probabilistic-earley-parser/grammar/grammar.js:111:16)
    at Object.<anonymous> (./parse_test.js:11:4)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions