PPG : a parser generator for extensible grammars

PPG is a parser generator for extensible grammars, based on the CUP parser generator. It provides the ability to extend an existing base language grammar written in CUP or PPG with localized, easily maintained changes.

Distribution of PPG

PPG was designed and written by Michael Brukman and Andrew C. Myers at Cornell University. It is part of the Polyglot Java extensible compiler toolkit. It can be also be obtained separately. Questions about PPG should be directed to Andrew Myers (myers@cs.cornell.edu).

PPG syntax

The PPG grammar syntax extends that of CUP with several new declarations:
  1. The first line of a PPG specification is where filename is a relative path to the inherited specification. A PPG spec can include a CUP spec or another PPG spec. It is an error for the chain of included files to contain a cycle.
  2. A PPG grammar specification can modify the inherited grammar using the following commands:
  3. PPG supports multiple start symbols in grammars. To specify which symbols may be used as start symbols, PPG provides the following syntax:
    start with S1 func1
    ...
    start with Sn funcn
    where each Si is a non-terminal symbol that you would like to start the parser with, every time you call the function funcn. PPG will automatically generate a new nonterminal symbol for each of these productions to differentiate between the different nonterminals that the parsing may start with now, and patch the grammar accordingly. After the parser class is instantiated, any of the funci can be called on it to parse the appropriate part of the grammar.
    Note: if you are using multiple inheritance, make sure to specify the symbols class you are planning to use with the -symbols switch. See running PPG section.

Running PPG

The syntax for invocation of PPG is
where

Semantics of PPG

The order of specification of commands is not important. The resulting productions for any nonterminal N is as follows:
The resulting available set of terminals is simply: where T is the set of terminals from base grammar, drop(T) is the set of dropped terminals using the drop command, newTerminals are terminals defined using CUP syntax. The resulting set of nonterminals is similar.
For precedence rules: if "precedence;" is specified by the PPG grammar, thus not inheriting any precedence rules from the base grammar, or where any newly defined precedence rules override any inherited precedence rules from the base grammar.