[antlr-interest] How to start?

Stefan Frey stefan.frey at solenix.ch
Mon Nov 23 02:11:59 PST 2009


Hi there i need some help,

i'm quite new to ANTLR and this is my first attempt. I'm trying to write a translator which converts files written in an so called operational language into java. 
Here a short example:

if (Demo1<> 0) and (Demo2<> 0) and (Demo3 <> 65535) and (Demo3 <> 0) then
	if (Demo3 >= 32768) then
		1.0 * Demo3 / Demo1 * Const1;
	else
		1.0 * Demo3 / Demo2 * Const2;
	endif;
else
	0;
endif;


should be converted to something like this:


public class Demo extends Synthetic {

	public Demo() {
		super();
	}

	protected boolean init() {
		String[] list = { "Demo1", "Demo2", "Demo3" };
		return setParametersNeeded(list);
	}

	protected void doComputation() {
		double Demo1= getValue("Demo1");
		double Demo2 = getValue("Demo2");
		double Demo3 = getValue("Demo3");
		double Const1 = Constants.Const1;
		double Const2 = Constants.Const2;

		if ((Demo1!= 0) && (Demo2 != 0) && (Demo3 != 65535)
				&& (Demo3 != 0)) {
			if (Demo3 >= 32768) {
				syntheticValue = Demo3 / Demo1* Const1;
			} else {
				syntheticValue = Demo3 / Demo2 * Const2;
			}
		} else {
			syntheticValue = 0;
		}
	}
}


So here are some of my questions :)
Is it possible to do this and how much effort will i probably take?
Where and how should i start? Are there any Examples or Samples of anything similar?


Cheers Stefan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091123/02913450/attachment.html 


More information about the antlr-interest mailing list