Monday, February 20, 2017

An idea: zubr - a Java code generator

I have an idea. I want to create a version of Perkun/Wlodkowic that works just like typical chess playing programs - i.e. without generating all the possible visible states. I want to use code that generates a game tree in runtime - based on the current state. In order to do that I will need a more powerful language than Perkun - I will need to write code in a general purpose programming language. One solution would be to embed an interpreter (like I did in Perkun2). Another one would be to enhance my own language. Another - the most interesting one - would be to create a code generator.

I mean a tool similar to yacc/bison with a specification that contains code in the target language. I choose the target language to be Java rather than C (for multiple reasons). The idea is to write a new tool (probably in C++) which would take a specification similar to this one:

//
// This is a zubr specification.
// When processed with zubr it generates Java code.
// The idea is based on yacc/bison generated parsers.

package optimizer;

%option class MyOptimizer
%option getinput own

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.Dimension;

%%

values
{
    value FALSE, TRUE;
}

variables
{
    input variable alpha:{FALSE, TRUE};
    hidden variable beta:{FALSE, TRUE};
    output variable chi:{FALSE, TRUE};
}

payoff
{
    set({alpha=>FALSE},0.0);
    set({alpha=>TRUE},100.0);
}

apriori
{
}

%%

// here we have remaining code (in Java) to be included in the optimizer class


 

I choose the tool to be named "zubr" which is derived from the Polish word "żubr" meaning a European bison.

As you can see I borrow quite a lot from the yacc/bison syntax. The middle part (between %% s) has Wlodkowic syntax, but the model generator will be written in Java.

The optimizer derived this way might be inherited or instantiated directly and used in your own Java program. The most important thing would be to achieve code based on Perkun specification with hundreds, maybe thousands of hidden variables. Current implementation of Perkun/Wlodkowic is not capable of doing that.

The tool "zubr" will be packaged in Perkun (hopefully in the version 0.1.5). In fact I already have a small prototype (based on Wlodkowic code).



No comments:

Post a Comment