Image Image Image Image Image Image Image Image Image Image

creativewidgetworks | July 16, 2017

Scroll to top

Top

10 Comments

GOLDEngine for Java

GOLDEngine for Java
Ralph

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.

 

 

Comments

  1. Leon von Mulert

    Any chance you can upload the binaries again? The current link in the readme is broken :/

  2. Ralph

    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.

  3. Atul Sachan

    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!

    • Ralph

      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.

  4. Leandry

    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!!

    • Ralph

      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.

  5. Cesar Luiz Javaroni Filho

    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 !

  6. Ralph

    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. 🙂

    • Cesar Luiz Javaroni Filho

      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.

      • Ralph

        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.

Submit a Comment