Source code

Revision control

Copy as Markdown

Other Tools

# jsparagus parser generator
This directory contains an LALR parser generator called "jsparagus",
written in Python.
This is used to build parts of the jsparagus JS parser in
jsparagus generates parsers only; it's "bring your own lexer".
Parser generators are complicated. Here's how this works.
1. **Input.** jsparagus can load **grammar files** that describe languages.
It's designed, in particular, to handle
but it can handle a variety of languages.
(For example, the code we use to parse the `esgrammar` file itself
is generated by jsparagus.)
To understand what a grammar is, see the comments in
2. **LALR.** jsparagus runs the
algorithm to generate parser tables. See
This code also rejects invalid or ambiguous grammars and so on.
There are a few comments in gen.py, but they assume a pretty solid
background understanding of parser theory. If you're starting from
scratch, check out:
* [Crafting
an excellent, challenging, free course with exercises.
* [The Dragon
by Aho et al. Often hard to follow, but it contains a
complete description of LR and LALR.
jsparagus has a few special features geared toward being able to parse
for more.
3. **Output.** The `emit` directory contains code for dumping the parser tables as
4. **Run time support.** Since the output is mostly just tables, there
has to be some code to actually look at tokens and the parser tables
and decide what to do.
For Python, that's in
For Rust, it's in
Because this code is currently tightly coupled to the JS lexer,
jsparagus is not a fully general Rust parser generator yet.
The Python code is more flexible.