开发者

Advice on creating an interpreted syntax in Java

开发者 https://www.devze.com 2023-02-12 02:38 出处:网络
I deal a lot with POS (Point of Sale) terminals in my line of work. They basically talk to a system endpoint that is written in Java that will the communicated with the back end system.

I deal a lot with POS (Point of Sale) terminals in my line of work. They basically talk to a system endpoint that is written in Java that will the communicated with the back end system.

For receipts, we will write the code in the endpoint that will generate the data that needs to be printed. These receipts can only take 40 characters per line, so we basically will hardcode each receipt type that needs to be printed.

What I would like to do is basically come up with a sort of scripting syntax that I could use to generate these receipts.

My idea is to have a GUI program where you can design the receipt such as

Welcome To John Doe Services
Your current balance is $(F4).Format(currency)

Or something of the like. With this i could then interpret the syntax $(F4).Format(currency) and actually pull the data and format it correctly.

I would love some advice in where i should start looking on how to d开发者_JS百科o this. I would like to write this in Java but I am not sure where to start. I would rather try and stay away from some substring magic.

Thanks in advance.

EDIT: Sorry i should have mentioned, the software that we extend was written in J++ so i cant use Java 5 or 6, the lastest Java i can use is 1.4


Scripting for the Java Platform is where you want to start, the Rhino JavaScript engine is already embedded in the Java 6 run-time so that is what you should look at using for ease of configuration.

If you insist on some Domain Specific Language the easiest place to start with that is ANTLR. There are some great books on ANTLR by the author Terrance Parr.


I see two approaches. One is a scripting language, or Domain Specific Language, which is the then applied to the receipt. JRuby is an obvious choice for this.

If you want to stick more closely to Java, then another approach is to use a template engine like Velocity or FreeMarker.

0

精彩评论

暂无评论...
验证码 换一张
取 消