imparse
Lightweight infinite-lookahead parser generator that supports basic grammars defined in a JSON format.

Purpose

This library makes it possible to rapidly assemble and deploy a parser for a simple language. It is intended primarily for languages that have an LL grammar.

Usage

The library can be included in a webpage in the usual way:

<script src="https://imparse.org/js/lib/imparse.js"></script>
          
The above introduces the imparse object into scope. To obtain a JSON representation of an abstract syntax tree given a grammar definition grammar (in JSON format) and a concrete syntax string str, it is sufficient to call imparse.parse(grammar, str).

Examples

Below are a few interactive examples of how the library can be used to define a grammar and parse a concrete syntax string into a JSON representation of an abstract syntax tree. You can change the grammar or input string and see the results immediately.

Basic Arithmetic

Grammar definition:
Input string:
Result:

Genetic Design

The example below is based on the language specified in Genetic Design via Combinatorial Constraint Specification by Bhatia et al. Note that the then operator has lowest precedence, the and and or operators are right-associative, and the unary operators have highest precedence.

Grammar definition:
Input string:
Result:

Acknowledgments

The development of this library is partially supported by the National Science Foundation under Grants #1012060, #1239021, and #1718135. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Collaborators who have contributed to the design and/or implementation of this library include Weston Vial, Eric Dunton, and Vidhu Nath.