JSGLR

Stratego -- Strategies for Program Transformation

JSGLR: An SGLR Parse Table Evaluator for Java

jsglr is a library for scannerless GLR parsing, implemented in Java. The jsglr implementation interprets the parse tables generated from grammers 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. The SDF2 package is necessary for this.

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

Example

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.

-- KarlTrygveKalleberg - 06 Jun 2008