gapotchenko / Turbo-CocoR

Turbo Coco/R is a compile-time compiler generator which takes an attributed grammar of a source language and generates a scanner and a parser for this language.
Other
3 stars 1 forks source link
coco-r compiler-generator csharp grammar parse parser-generator parsing scanner-generator

Turbo Coco/R

Turbo Coco/R is a compile-time compiler generator which takes an attributed grammar of a source language and generates a scanner and a parser for this language. It is based on the de-facto Coco/R standard and extends it to be more useful in commercial settings.

Basics

Turbo Coco/R is very similar to once popular lex and yacc tools and their open-source flex and bison counterparts. The main distinction of Turbo Coco/R is that it provides the support for multiple programming languages and generates both a scanner and a parser from a provided grammar file.

The produced scanners and parsers are tiny, do not have external dependendencies and thus can be embedded into any project at the source level.

The scanner works as a deterministic finite automaton. The parser uses recursive descent. A multi-symbol lookahead or semantic checks can resolve LL(1) conflicts. Thus the class of accepted grammars is LL(k) for an arbitrary k.

Turbo Coco/R rigorously follows the baseline Coco/R standard while providing a plethora of improvements, extensions, and integrations.

Getting Started

  1. Install Turbo Coco/R tool using .NET package manager:

    > dotnet tool install --global Gapotchenko.Turbo.CocoR
  2. Create your first attributed grammar file:

    > turbo-coco new grammar MyLang.atg
  3. Create the customizable frame files* for a scanner and parser:

    > turbo-coco new frame scanner parser

    * A frame file defines the basic code structure of a source file generated from the grammar.

Now you can generate the actual scanner and parser source files for your grammar:

> turbo-coco MyLang.atg

Once generated, the files are ready to be compiled as parts of your project.

For further guidance, see the examples.

Build Integration

In addition to the traditional command line approach, Turbo Coco/R offers automatic build integration to streamline the development process.

Requirements

Please note that:

Licensing

Turbo Coco/R is licensed under GNU General Public License v2.0.

If not otherwise stated, any source code generated by Turbo Coco/R (other than Turbo Coco/R itself) does not fall under the GNU General Public License.