jga: Generic Algorithms for Java, release 0.7 is now available
The hilights of this release are;
* Support for the Java 1.5.0_02
* The new FunctorParser (and it's typesafe extension GenericParser) allow functors to be described using java-like syntax: the parser creates the functor that implements the logic described in the expression.
* Hacker's Worksheet is the next phase in the evolution of the Spreadsheet engine included in the prior release. This application uses the FunctorParser to implement a spreadsheet whose expression langauge looks like java in most respects.
This release is compatable with either Java 1.4 or Java 1.5.
+ is there a way to extend the current
GenericParser with new operands, literals, ...?
+ can the semantics of an existing operator,
literal ,,, be changed?
JFXG is implemented as a JavaCC grammar -- such grammars are not designed to be extended directly, but if you understand JavaCC well enough, I suppose you could add pretty much anything you want. However, the existing grammar is based directly on standard Java 1.5, so it won't support adding new operators unless they are added directly into the grammar.
There's a little information about the current extension points here:
You can override the reservedWord, reservedField, and reservedFunction to add to the existing grammar, but you'll have to understand the FunctorRef implementations in the parser package. I've done this in the swinglabs databinding project to add database summary functions, for example.
The JFXG parser also supports static import, so you can configure an instance of the parser with static methods in any class you have handy: this isn't quite the same as extending the language with new methods, but it is close.
I'd designed the arithmetic functors in jga to support any implementation of java.lang.Number (I've been meaning to document this in my blog, but haven't gotten around to it). To add support for a new number implementation requires implemeting net.sf.jga.fn.arithmetic.Arithmetic or net.sf.jga.fn.arithmetic.IntegerArithmetic (whichever is appropriate). You register your implementation with the ArithmeticFactory, and all of the existing functors in that package will support your number type. With this in place, you should be able to do things like:
new Fraction(1,2) + new Fraction(3,4)
I'd had the intention of trying to allow for parsing of arbitrary number types, so maybe for Complex numbers, you could use expressions like
3i+4 * i-1
There'd have to be some limits -- it'd probably require that your numbers be of a form similar to scientific notation: a string of digits, that uses '.', '+', '-', and single letters as punctuation.
I never got around to implementing that, but I think it'd be really cool.
Outside of the arithmetic operators, there is no support for redefining the semantics of the built in operators. The java grammar really isn't set up to support that.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.