Parsing System (v0.7)
|
Goldie OverviewThe process for using Goldie is just like the process for GOLD Parser Builder: 1. Write a grammar in the .grm languageHere is a simple example of a grammar definition: ! This grammar defines a simple language consisting of
! positive integers separated by a plus sign.
"Start Symbol" = <List>
Number = {Digit}+
<List> ::= <List> '+' Number
| Number
One of the nice things about the GOLD/Goldie systems, unlike most other parsing systems, is that there's no code embedded in the grammars, so grammars are write-once-and-reuse. In other words, if you write a grammar to use in one tool, you can reuse the exact same grammar for any other tool - even if the two tools are written in completely different languages! More information about the grammar description language used by GOLD and Goldie, including links to premade grammars, can be found on this page: Grammar Definition Language 2. Compile the grammar to .cgt formatGoldie 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:
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 grammarGrammar files can be compiled in a number of ways:
3. Use a GOLD engine to load the compiled grammar and parse a sourceAny 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. |