wxGoldParser for wxWidgets

wxGoldParser is an engine for GOLD Parser written in C++ for wxWidgets. Unlike common compiler-compilers, the GOLD Parser does not require you to embed your source code directly into the grammar.  Instead, the application analyzes the grammar and then saves the parse tables to a separate file. This file can be subsequently loaded by different engines (in different languages), and now also used in wxWidgets.

The wxWidgets engine is ported from the Delphi 5 version from Alexandre Rai, and slightly modified to run faster and to be used easier and more reliable under wxWidgets. The Delphi example code is almost ported 100% to wxWidgets to show others which parts of the code are changed, and ofcourse to see if the engine would give the desired result.

The source can be downloaded from here and contains:

  • The wxWidgets engine C++ source
  • Makefiles for Linux and VS6 / VS7 projects for Windows
  • The original engine plus example source from Alexandre Rai
  • An extra example formula calculator to show how to work the reductions
  • Skeleton templates for GOLD Parser to be used in the application

The wxGoldParser engine is grammar independent, which means if you download a ready made compiled grammar file (for any language you want) it can handle it right away. Simply use the skeleton templates to generate a ready to go class and header file for your parser. Check out the formula parser example inside the source to see how to use it (it uses a skeleton program).

wxGoldParser is freeware and distributed under the wxWidgets license

The following screenshots show the Grammar Tester:

The grammar tester is the program Alexandre Rai created to test his grammar. I ported it to wxWidgets to check if the result would be the same. And see here, it is!

Delphi Version (Windows)

wxWidgets Version (Windows)

wxWidgets Version (Linux)

The following screenshots show the formula parser:

The formula parser is an example using the generated skeleton code, and passing reduction results up the parser stack.

wxWidgets Formula Parser Example (Windows )

wxWidgets Formula Parser Example (Linux)

Latest changes

v1.0b This is the first release.

Todo list

  • The code is ported from Delphi to wxWidgets C++ so it needs to be cleaned up and optimized. As you know, it is wise to first get it working, then get it optimized. This will be done eventually.
  • Rework some object class hierarchies to make things more logical. This is not visible to the developer, the API will remain the same
  • The source feeder needs a file / stream version, and possibly a way to stack files when an include mechanism is needed
  • The API needs documenting in Doxygen
  • A document needs to be made to show how Lexx / Yacc compares to the GOLD Parser engine. See the formula parser's ReplaceReduction routine to get a pretty good idea. This version works with wxVariant classes to pass data up the stack instead of union structs.

How to use the wxGoldParser

  • Make your grammar in GOLD Parser, and compile it
  • Make sure you downloaded the latest source
  • from wxGoldParser
  • The best way is generate your code with the skeletons from GOLD Parser
  • Add the include path to the wxGoldParser engine in your options
  • Modify the generated code slightly (unfortunately some pragma's are added to force errors if you haven't changed the code yet)
  • Build the library by executing the makefiles (Linux) or projects (Windows)
  • Add the compiled library to your makefile (or project) check out existing project files for examples
  • Add the generated skeleton code to your source and modify it to create your parser
  • Study the test programs to see how to use the engine and reduction tree
  • If you still don't know, email me

The skeleton templates

The skeleton tempates are located in the samples/engine directory in the wxGoldParser source. To use the latest ones, copy these to the GOLD Parser's template directory. In the program, after you compiled your grammar or loaded a compiled grammar, select "Create a skeleton program" and select the wxGoldParser skeletons (there are two you need to do!) to generate the code.

After generating the code, modify the .cpp file to include the proper file you generated. Unfortunately GOLD Parser only generates one file a time so it's not aware of the proper header file name. If you forget to do it, there is an error pragma notifying you of this issue.