Useful Information about LPG

This page contains various sorts of useful information about LPG, the LALR parser generator included with IMP. (LPG was formerly known as JikesPG.) LPG has its own SourceForge project.

IMP does not require any particular parser-related technology, but it does need a way of producing a model (AST) for the source text. We've adapted LPG to support the parser- and AST-related interfaces on which IMP depends, and we have made it easy to use LPG through IMP. For instance, there are IMP wizards for using LPG to generate a parser and AST, and we have provided an IMP-based IDE to facilitate the editing of LPG grammar files.

This page addresses the following topics:

LPG Quickstart for IMP Users

The IMP installation includes a version of LPG for generating a lexer, parser and related components in support of the instantiation of an IMP IDE for a new programming language. The lexer and parser are generated from "grammar" files that specify the lexer and parser grammars for the language. IMP uses LPG with three grammar files: a "KeywordLexer.gi" file (".gi" stands for "grammar include"), which specifies the keywords of the language, a "Lexer.gi" file, which specifies the general lexical grammar (given the keyword lexer), and a "Parser.g" file (".g" stands for "grammar), which specifies the parser garmmar (given the general lexer).

When the "New LPG Parser" wizard is run on a IMP project, it installs an LPG builder in the project, creates a parser package in the source folder of the project, and copies in three default grammar files. The builder then generates Java classes for the lexer, parser, and related components, using templates provided with LPG and IMP.

A brief overview of the sections of the LPG grammar files that IMP users may encounter (though note that not all sections will occur in all files):

What do these mean for the IMP user?

The LPG grammar templates used by IMP, along with the Java classes generated from these, usually give some examples and brief instructions about how the files should be completed for a new language.

Running LPG As an External Tool

LPG can be run manually in Eclipse as an external tool. To be able to do this, you must have the plugin project lpg.generator and the appropriate platform-specific plugin fragment (e.g., lpg.generator.macosx86) imported into your workspace. These projects contain the LPG executable and the platform-independent template/include files, as well as the Eclipse launch configuration (in the folder ".launchConfigurations). When this project is in your workspace, the launch configuration should be recognized automatically and should be available through the External Tools menu. (To open the External Tools dialog, navigate "Run" -> "External Tools" -> "External Tools ..."; you should then find LPG under "Programs")

Important note on system compatibility: As of March 2010, the only platforms for which IMP distributes LPG are Windows, Mac OS X (32- and 64-bit) and Linux (32- and 64-bit). However, you should be able to create an executable for any system that has an ANSI C compiler and POSIX-compliant 'make' by downloading the source code from the LPG project on SourceForge and building it using make. Alternatively, if your system supports the execution of another O.S. environment within a virtual machine, you may be able to run one of the provided executables under that (see Troubleshooting below).

You can also run LPG manually as an external tool on a grammar specification file (".g" or ".gi" file). To do so, select the grammar file and then invoke LPG from the External Tools dialog. If you run LPG on a ".g" file, LPG will generate a complete set of tools (parsre, lexer, and keyword filter). If you run LPG on a ".gi" file, you can generate just the lexer or keyword filter (depending on the specific file).

The default parameters of the launch configuration for use with IMP are as follows:

If your workspace is configured differently from what the default presumes, or if you have renamed the relevant projects, then you will need to adjust these parameters accordingly.

LPG Documentation

There is documentation for LPG on the LPG website.

Troubleshooting:

LPG build on Linux doesn't run correctly: One LPG user tried building the LPG executable from source on a Linux system and got the same errors when he tried to use it as when he ran the Linux version of the executable that is provided in the LPG release from SourceForge (see the message thread "Problems with LPG parser", dated 9/17/2007, in the eclipse.technology.imp newsgroup on news.eclipse.org, started by Oleg Murk, olegm@gmail.com). He was able to get the Windows version of LPG running on his system under the Windows emulator Wine:

The work-around is to replace the contents of the file
$ECLIPSE_HOME/plugins/lpg.runtime_2.0.18/lpgexe/lpg-linux_x86 with a script like

        #/bin/bash
        `echo wine $0 $* | sed "s/lpg-linux_x86/lpg-win32_x86.exe/" | sed
        "s/\"-include/-include/" | sed "s/'\"/'/"`
        
and make it executable:

        $ chmod u+x $ECLIPSE_HOME/plugins/lpg.runtime_2.0.6/lpgexe/lpg-linux_x86
        
Incubation
Incubation