UniCC LALR(1) Parser Generator
|Download||v1.4 (source code) (more)
v1.4 (MS Windows setup)
UniCC is a target-language independent parser generator.
UniCC (UNIversal Compiler Compiler) is a LALR(1) parser generator. It compiles an augmented grammar definition into a program source code that parses the grammar. Because UniCC is intended to be target-language independent, it can be configured via template definition files to emit parsers in nearly any programming language.
UniCC supports parser code generation for the following programming languages so far:
- C is fully supported (and reference implementation),
- C++ is well supported,
- Python is well supported,
- ECMAScript is prototyped in a stub, but may come soon.
More target languages can easily be added by creating specific target language templates.
This is the full definition for a four-function arithmetic syntax including their integer calculation semantics (in C).
#!language "C"; // <- target language! #whitespaces ' \t'; #lexeme int; #default action [* @@ = @1 *]; #left '+' '-'; #left '*' '/'; //Defining the grammar calc$ -> expr [* printf( "= %d\n", @expr ) *] ; expr -> expr '+' expr [* @@ = @1 + @3 *] | expr '-' expr [* @@ = @1 - @3 *] | expr '*' expr [* @@ = @1 * @3 *] | expr '/' expr [* @@ = @1 / @3 *] | '(' expr ')' [* @@ = @2 *] | int ; int -> '0-9' [* @@ = @1 - '0' *] | int '0-9' [* @@ = @int * 10 + @2 - '0' *] ;
To build and run this example, do
$ unicc expr.par $ cc -o expr expr.c $ ./expr -sl 3*10-(2*4)+1 = 23
UniCC features the following, unique tools and possibilities.
- Powerful BNF-based grammar definition language
- Full unicode support
- Build-in lexical analyzer
- Grammar prototyping features
- Virtual productions
- Anonymous nonterminals
- Semantically determined symbols
- Two parser construction modes allow the use of different algorithmic approaches relating the whitespace handling
- Target-language independent parser development
- Template-based program-module generator and XML-based parser description file generator
- Platform-independent (console-based)
- Standard LALR(1) conflict resolution
- Supporting C, C++ and Python target languages so far
The UniCC User Manual is the ultimative guide and reference for the UniCC parser generator.
It covers a general feature introducion in to UniCC, a beginner's tutorial guiding into the topic 'parsing' in general and how to implement parsers with UniCC, a UniCC compiler and language reference guide and a user's reference relating to the Standard C Parser Template. As an state-of-the-art example, the compiler for a simple programming language called XPL is developed alongside the howto guide.
The manual will be continously be updated and extended with more or detailed information and chapters. Hopefully it answers all of questions coming up when UniCC shall become the workhorse of your upcoming compiler project. If not, don't avoid to drop a mail, to get individual support and help with the UniCC Parser Generator and its subsequent modules.
The UniCC LALR(1) Parser Generator can be used, modified and distributed under the BSD open source license.