JSGLR

Stratego -- Strategies for Program Transformation

JSGLR: An SGLR Parse Table Evaluator for Java

The jsglr library implements scannerless GLR (SGLR) parsing in Java. The library provides an interpreter for parse tables generated from grammars written using SDF. The jsglr library can load parse tables for the sglr version 3.16 from textual ATerms, TAF or BAFs (compressed, binary ATerms).

Note that the parse tables cannot be generated from SDF grammars by the jsglr package. You will have to install the SDF package for this.

For more details, see http://www.spoofax.org/jsglr.html

Usage

Initializing and using jsglr from your application is easy:

String inputFile = ...
ParseTableManager ptm = new ParseTableManager();
SGLR sglr = new SGLR(ptm.getFactory(), ptm.loadFromFile(parseTable));
ATerm t = sglr.parse(new FileInputStream(inputFile));

First, the ParseTableManager is instantiated. This is a registry of all loaded parse tables. Loading large parse tables takes a bit of time, so pre-loading all the parse tables you need into the registry will save you time if you need to parse repeatedly.

Second, the an SGLR instance is created, and "inherits" the ATerm factory from the ParseTableFactory. Here, we use the ParseTableManager to cache the ParseTable while it is loaded.

Third, parsing is just a matter of calling the parse() method on an object of class SGLR. The result is an ATerm, or null, if the parse failed.

Error Recovery in JSGLR

JSGLR provides supports for parse error recovery, which is essential for applying the parser in an interactive environment. The Permissive Grammars project provides further information on this topic.