Example Grammars¶
CongoCC ships a set of example grammars in the examples/ directory of the
source distribution. They range from tiny demonstrations to complete
programming-language grammars, and most are generated and tested across several
target languages by ant test.
Two senses of “language” meet in the table below, and it helps to keep them apart:
the language a grammar defines — what its generated parser recognizes (Java, JSON, Lua, …); this is what the example is named for; and
the target languages CongoCC generates that parser in (
-lang java|python|csharp|rust).
So the python example is a grammar for the Python language that is itself
generated as a Java, Python, C#, and Rust parser. Rust generation is gated
behind the rust.enabled build flag (see Rust).
The examples¶
Example |
Grammar file(s) |
Language defined |
Targets generated |
|---|---|---|---|
|
|
A simple arithmetic-expression language. |
Java, Rust |
|
|
A subset of IBM’s CICS embedded command language; demonstrates repetition cardinality constraints. |
Java, Python, C#, Rust |
|
|
CTL, CongoCC’s own template language used for code generation. |
Java (see notes) |
|
|
The C# language; |
|
|
|
The Java language; identifier-definition includes cover JDK 8 through 26. |
Java, Python, C#, Rust |
|
|
JSON, and JSON with comments. |
Java, Python, C#, Rust (both grammars) |
|
|
The Lua language. |
Java, Python, C#, Rust |
|
|
The PHP language. |
Java (see notes) |
|
|
A barebones C#-style preprocessor for |
Java, Python, C# |
|
|
The Python language. |
Java, Python, C#, Rust |
|
|
The Rust language. |
Java |
|
|
A SQL expression language. |
Rust |
Notes¶
Split grammars. Many examples divide their grammar across files: a main grammar that
INCLUDEs a separate lexer (for instanceLuaLexer.ccc) and, for the programming languages, an identifier-definition file. The Java example carries several —Java8IdentifierDef.cccthroughJava26IdentifierDef.ccc— because the set of legal identifier characters changed across JDK versions. TheseINCLUDEd files are summarized compactly above and are not generated on their own.Examples without a build file.
congo-templates(the CTL template language) andphphave nobuild.xmland so are not part of the automated cross-target build; CTL is generated as Java as part of building CongoCC itself.Targets reflect the build files. The target set shown for each example is what its
build.xmlactually generates in the current source. Some examples — notablysqlexprand therustlanguage grammar — are generated for a single target rather than all four.