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:
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?
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:
Note that this will use the executable located in the appropriate platform-specific plugin fragment.
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.
There is documentation for LPG on the LPG website.
#/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