GOLDEngine for Java

The GOLD Parser is a parsing system developed by Devin Cook that can be used to parse existing programming languages, scripts, or structured data files. It can even be used to develop your own domain specific language (DSL).  There are many tools available to do similar tasks, LEX/YACC for instance, but what sets the GOLD system apart is the interactive nature of the grammar development and testing.

The GOLD system consists of three components:  the GOLD Builder, a compiled grammar file, and an engine that will use the compiled grammar file to process source input files.

The GOLD Builder is a Windows GUI application that allows a user to create or modify a language grammar (set of symbols and rules) and then test the grammar against sample input. Once you are satisfied with the grammar, the Builder will then generate a compiled grammar file, an optimized table of symbols and rules.  The Builder is also able to generate a sample template file for a number of engines written in many languages.

GOLDEngine for Java is a Java implementation of an engine that can process source input using the compiled grammar files (CGT and EGT format) created by the GOLD Builder. The engine is able to act as a language interpreter, compiler, or language translator depending upon how the production rules are implemented.

The source for the engine as well as some examples can be found on GitHub goldengine.  I also have a link to a PDF document containing the presentation slides from a talk that I gave at the McHenry County Software Craftsmanship meeting in July 2012.

 

 

13 thoughts on “GOLDEngine for Java

  1. Seemed to have missed the memo about GitHub discontinuing downloads of non-repository files. Updated link on GitHub to download from here. Thanks for letting me know.

  2. Hi Ralph,

    I am using GOLDEngine library in java project for analyzing mysql file, which is working properly, but when i am using MSSQL file for analysis, this library get fails as its Reduction object and tree does not get create. so please suggest me if there is any way to analyze MSSQL file using GOLDEngine library.

    Thanks!

    1. Many errors are a result of definition of the grammar. However, a few bugs have been found in the Java engine in the parser, which are fixed in more recent versions. If you continue to have problems with this particular grammar, you can send it to me, ralph at creativewidgetworks dot com and I’ll have a look.

  3. Hi Ralph, I’m a pioneer in this subject, I need more info about the engine, for example, I load the grammar ok, and generate the tree perfectly, but I need traverse the tree, I don’t find any info about that. Please help me!!

    1. By traversing the tree, I understand that to mean that you want to know how the tree is used to “execute” your code. In the Java engine, you need to create a series of RuleHandlers that handle the productions. See the examples in the library to see how a RuleHandler is implemented. Devin has added my code generation template, which will create one Java file that contains all the required RuleHandlers. You need to split out the individual handlers into separate Java files because of the way GoldBuilder works.

      Here are the steps to produce the RuleHandler and shell for a given grammar:

      1. Launch GoldBuilder and load your grammar into it.
      2. Project->Analyze
      3. Project->Create LALR parse tables
      4. Project->Create DFA lexer tables
      5. Project->Save tables (optional)
      6. Project-Create skeleton program (Languge: Java Engine: Iden Java engine)
      7. Save the Java file that was created
      8. Edit the Java file, splitting out the handlers into individual classes.
      9. Implement the functionality in your rule handlers

      This and the examples should get you started.

  4. Hello Ralph, I have taken a compiler course at College, but the teacher uses yacc/bison and I don’t think they are as user friendly as GOLD, so I decided to use GOLD for my project, but I struggling with the lack of guides on how to use the engine, I’ve read your examples but I’m not sure about the rule handlers, you have separated them from the java files, but u also have implemented some tests liek AssignTest, DisplayTest, and so on.
    My doubt is: I need them for my code to work ?
    Or just the rule handlers?
    It’s hard to find GOLDParse guides these days, your examples are by far the best reference I’ve had so far, Thanks !

  5. Devin’s GOLD Builder is a great tool for parser creation. I ported Devin’s reference engine to Java because an older one written by someone else became obsolete and couldn’t be used without a lot of work. My engine was a quick port and I knew that the implementation and documentation could be improved. It was my hope that the unit tests and examples would be sufficient for someone to get their own projects up and running.

    The rule handlers glue the parsed source code to the actual code that is generated (in the case of a compiler) or interpreted (like the examples I provided).

    Although I intend to revisit the project to improve both the implementation of the engine and making it easier to use the rule handlers, it isn’t a priority for me at the moment. Still, I revisit the topic of parsers from time to time and I may update the engine at some point — I have a refresh of my expression-evaluator project that I wrote for our local Software Craftsmanship group that will be updated on GitHub before long, so there is hope. 🙂

    1. Hello Ralph, I was able to make my own compiler, thanks to you! 😉
      Your examples were clear, I think that my first contact with a parser was a little scary, let’s say that my teachers here wanted me to use flex/byson, but I found it a little too hard to handle and I’m much more comfortable with OOP than using pointers in C/C++.
      I had some issues with the rulehandlers, because some times it just didn’t process my notation for @ProcessRule, one example was trying to handle the creation of a variable and a value to it at the same time.
      First I did something like this:
      @ProcessRule(rule = {
      ” ::= var Id ‘;'”,
      ” ::= var Id = ‘;'”
      })

      Although I treated reduction sizes in the constructor, the parser wasn’t able to find the second Processing rule.
      What I simply was breaking it in 2 processing rule classes and everything worked fine.
      I have no idea why.
      My compiler is written in a mix of portuguese/english ( group partners prefer portuguese over english :S ) but I can send you over git if you wish.
      With your projects I was able to finish this work in time, although I didn’t try to evaluate variable types, that was one of my plan, but I hadn’t the time to implement it.
      Thank you for all the help!
      I wish there was more bibliography and sources for GOLD, I think they were all outdated and no one took time to just get some of the websites running again.
      If you ever visit Brasil send some notification and come drink a coffee.
      Regards,
      Cesar Javaroni.

      1. The way the rule handlers are matched (by the engine) has created an issue for some grammars, as you observed. This was my first attempt at using annotations to mark the handlers and it was only after others were using the engine did this issue reveal itself. I may go back and revisit the implementation as I have done for my other parsing project.

        I’m happy that you found GOLD Builder and my engine for it useful. I’ll take you up on that cup of coffee if I find myself in Brasil.

        Muitas felicidades.

  6. Hi Ralph,
    I am PhD student and I am looking for the best tool to generate a parser. I was struggling with lex/Yacc until I found Gold Parser tool and your great code on GitHub.

    Can you please answer my questions..
    1. after I separate rule handler, should I follow the organization like simple 2 and simple 3, what else should I provide beside rule handler to make my compiler works?
    2. I am not able to run simple 2 and simple 3.. I build the project successfully using mvn.
    then I did the following
    cd to where simple2 folder
    then, run Hello.txt -tree but it doesn’t show anything
    Also, I tried to run Simple2. java by using
    java -jar simple2.jar Hello.txt -tree but I got error. simple2.jar is not accessible.

    Please help me to implement your examples..

    Thanks a lot in advance..

    1. I am SO sorry that I didn’t see your comment earlier. I have been away and haven’t been receiving notifications. If it isn’t too late for a response, allow me to reply.

      The first problem is that Maven won’t build a jar with all of the required classes for Simple2/3. Originally, ant was the means to build the project and I added Maven so I can deploy to the Maven Central Repository. In my haste with the refactor to remove the example languages from the goldengine.jar, I failed to address this situation. Until you brought this to my attention, I didn’t know I had introduced a problem.

      I am modifying the Maven build so it will build the standalone engine as well as executable jars for Simple2, Simple3, and SimplyPy. This is nearly complete and will have that finished before the end of the weekend. That will address your issues with the demos and provide a structure to build your own language jars, if you so desire.

      If you are using Maven, then I would consider using the new structure as I think it is clean and allows sample source files to be included in the jar.

      I’ll update this thread when you can pull down the updated code.

  7. Okay, if you pull and build master using Maven, the jars will build as expected (see the respective target folder). README.md has been edited to be more concise and building via Ant has been removed.

Leave a Reply

Your email address will not be published. Required fields are marked *