Marpa is an implementation of an Earley parser for Perl.

Earley parsers are parsers which can handle very ambiguous grammars in cubic time in the general case - O(n3).

There are some Earley parsers or recognizers which are not fully usable tools missing vital aspects such as being able to iterate through each parse tree in the parse forest when the parse was successful but ambiguous.

I'm only interested in tools which support access to the full abstract parse forest.

Marpa uses a C library, libmarpa, for its backend, and it's open source so other projects can integrate it.

I'm looking for an implementation of an Earley parser for Node.js that's either built on libmarpa, or is comparable to it.


  • Must support grammars with at least as much ambiguity as Marpa can handle.
  • Must not be just a recognizer but a full parser producing a parse forest.
  • Must not produce merely one possible parse tree for ambiguous inputs, but a full parse forest.
  • Marpa is a C library, so it might be possible to compile Marpa into JavaScript using Emscripten. JavaScript Moony Parser can parse strings using ambiguous grammars, but I do not know whether it can generate a full parse forest. Mar 20, 2015 at 21:04
  • At the time I played with Moony Parser I recall it only returned one possible parse and thus was a recognizer but gave you no way access and process the alternative ambiguous parses in the forest. This is essential when a grammar is inherently ambiguous but that can be sorted out by the semantics at the next level. It may have changed since then. Mar 21, 2015 at 1:21
  • The Nearley parser for node.js looks very promising, since it is able to generate an array of multiple parsings for ambiguous grammars. I'm not sure if it will produce an entire parse forest in all cases, though. Aug 22, 2015 at 23:12
  • 1
    Also, it might be possible to automatically translate Marpa's source code into JavaScript using Perlito. I haven't yet tested this solution, though. Aug 22, 2015 at 23:16

2 Answers 2


Please, excuse my self-promotion - but recently I developed tiny JavaScript implementation of Earley parser, which can extract multiple syntax trees (which have very simple structure, and can be easily traversed).

The library (single JS file) and examples can be found here: https://github.com/lagodiuk/earley-parser-js

  • 2
    Self-promotion is welcomed as long as it is disclosed and not spam. Clearly, yours is the welcomed kind! :-) Nov 4, 2015 at 5:10

Another suggestion is nearley (https://github.com/kach/nearley). The project is actively being developed and has decent speeds, can take advantage of tokenizers, etc.

  • Documentation isn't thorough, but it seems to be good. Having a built-in support for lexer/tokenizer would be a welcome bonus; presently, you must use a third-party module like Moo.
    – Harry
    Apr 27, 2021 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.