Parsing System (v0.7)
Goldie Home (v0.7) -> Getting Started -> Goldie Overview

Goldie Overview

The process for using Goldie is just like the process for GOLD Parser Builder:

1. Write a grammar in the .grm language

2. Compile the grammar to .cgt format

Goldie uses the LALR(1) and DFA algorithms to parse source. Both of these algorithms can be driven completely by tables of raw data, so Goldie requires grammars be compiled into these tables before they can be used. This provides certain benefits:

  • The grammar definition itself can be parsed ahead of time, instead of on-the-fly. (Although, this is typical of just about any parsing system.)
  • Grammars can be checked for errors before they're used. (This is also typical.)
  • The code to parse a source can be written once and reused for any grammar, even without automatically-generating any code. This is very rare among parsing systems.

That last benefit is very powerful as it allows programs to be written that operate on user-created grammars without compiling any software or using DLL-based plug-in systems. Goldie's Parse tool and Sample Generic Parse sample make use of this ability.

Of course, this doesn't prevent automatically generating source code for a parser as other tools such as ANTLR do. In fact, GOLD has a full template system that does exactly that. Goldie doesn't actually make any use of it, but GoldieLib does offer a static-style which fills a similar role for D v2.x users.

How to compile a grammar

Grammar files can be compiled in a number of ways:

  • Goldie's GRMC: Grammar Compiler

    A cross-platform command-line tool.

    >goldie-grmc grammar.grm Or: >goldie-grmc grammar.grm -o:output.cgt
  • GOLD Parser Builder

    A .NET-based tool in GUI and command-line versions.
  • GoldieLib's Language.compileGrammar* functions

    A D v2.x API interface. This can be useful for building general language-processing tools. In fact, this is what GRMC: Grammar Compiler uses.

    string grammar1 = "!* grammar definition here *!"; Language lang1 = Language.compileGrammar(grammar1); // Or: Language lang2 = Language.compileGrammarFile("grammar2.grm"); // Optionally save: lang1.save("grammar1.cgt"); lang2.save("grammar2.cgt");

3. Use a GOLD engine to load the compiled grammar and parse a source

Any GOLD-compatible engine can be used to load the compiled grammar and parse a source. Such engines are available for a wide variety of languages, since they're fairly easy to make. Goldie includes GoldieLib which serves as just such an engine for D v2.x.

Each engine is used differently, and their features and APIs can vary greatly. To start learning how to use the GoldieLib engine, see the following:

Next: Beginner's Tutorial

Also:

Additionally, see the Goldie's Tools page for various tools that may be helpful when using Goldie.