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 and you may still find references to JikesPG in the IMP documentation and code.)  LPG also has its own SourceForge project at http://sourceforge.net/projects/lpg/.

IMP does not require any particular parser-related technology, but it does require support for parsing and AST representation.  We like LPG and have adapted it 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 section addresses the following topics:
LPG Quickstart for IMP Users
Running LPG as an External Tool
LPG Documentation
Troubleshooting

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 a 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 Programming Language wizard is run on a IMP project, it installs a 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 (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 project lpg.runtime.java imported into your workspace.  This project contains both the LPG executable (in the folder "lpgexe") and 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 18 Sep 2007 only the Windows version of LPG is being maintained and only the Windows version of the LPG executable is up-to-date.  You may be able to create an executable for other systems by downloading the source code from the LPG project on SourceForge (http://sourceforge.net/projects/lpg/) and building it locally.  Alternatively, if your non-Windows system has a Windows emulator, you may be able to run the Windows version of LPG under that (see Troubleshooting below).

To run LPG as an external tool on a specific grammar specification (".g" or ".gi" file), 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:
${workspace_loc:/lpg.runtime.java/lpgexe/lpg-win32_x86.exe}
${container_loc}
-include-directory=${workspace_loc:/lpg.runtime.java/templates};
${workspace_loc:/org.eclipse.imp.lpg.metatooling/templates} ${resource_loc}
(note that the second second argument refers to an IMP project that contains IMP-specific templates).

If your workspace is configured differently than what the default presumes, or if you have renamed the relevant projects, then you may need to adjust these parameters for your particular situation.

LPG Documentation


There is documentation for LPG on the LPG website at http://sourceforge.net/projects/lpg/.


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 trick is to replace the contents of file
 $ECLIPSE_HOME/plugins/lpg.runtime_2.0.6/lpgexe/lpg-linux_x86
with a script
----------------------------
#/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




Get Firefox!