Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext/Xbase for writing complex math expressions
Xtext/Xbase for writing complex math expressions [message #988925] Mon, 03 December 2012 14:14 Go to next message
Matthew Davis
Messages: 269
Registered: July 2009
Senior Member
Greetings,

The Eclipse STEM project is considering Xtext (/Xbase) to assist in writing mathematical expressions.

Here are some things we'll need to do with it:

1. Write complex math expressions w/variables and function calls. To start, our expression will be single line with no assignment.
2. Generate Java code that is inlined in EMF-generated EOperation method bodies
3. Scope and types are custom and mapped to fixed JVM elements at code generation.
** In-scope variables are custom-typed and come from several configuration sources and map to different JVM elements depending on type (based on the STEM API)
** In-scope functions provided by plug-ins via extension registry and map to static methods
5. Provide editor w/content assist, validation, etc

It seems like Xbase is a good place to start. Our question is whether Xbase is appropriate, or if we should just start with our own grammar.

Thanks
Re: Xtext/Xbase for writing complex math expressions [message #989081 is a reply to message #988925] Tue, 04 December 2012 10:00 Go to previous messageGo to next message
Martin Baker is currently offline Martin Baker
Messages: 31
Registered: July 2009
Member
> Write complex math expressions w/variables and function calls.

The following are just a few random thoughts of my own since I am also interested in using xtext for mathematics, hopefully someone more knowledgeable than me will reply to your message.

It seems to me that it is quite difficult to write mathematical expressions in plain text if they contain stuff like: Integrals, summations, complicated denominator, matrix, vector, suffix, superscript and so on. It would be much more readable if these things could be coded in MathML (that is: XML). I've often thought that it would be good if the xtext grammar could optionally be replaced with something like an XML schema but all the other features on xtext like UI editor, code generation, scoping and so on could be retained? The language would need to define how each element is displayed.

I wonder if Scala-style Case Classes would help with decomposing expressions. It would help even more if this pattern matching capability could be extended to work across algebra types (integer, real(double), complex, vector, matrix and so on). The point being that, in algebra types like this, operations like '+' and '*' are heavily overloaded and there are cross-cut issues between expressions and algebra types.

I find it messy converting expressions to object oriented form, I know that xtend/xbase allows e1+e2 to be coded as e1.operator_plus(e2), for example, but I still find it messy. For instance if we want to support float * matrix and also matrix * float do we have to modify both the float and matrix classes?

If xbase is not used, is it easy to customise floating point literals (DOUBLE)? Is it possible to use exponent notation without making 'e' into a keyword?

Martin
Re: Xtext/Xbase for writing complex math expressions [message #989293 is a reply to message #988925] Wed, 05 December 2012 09:48 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1761
Registered: July 2009
Senior Member
Hi Matthew,

Am 12/3/12 8:14 PM, schrieb Matthew Davis:
> 1. Write complex math expressions w/variables and function calls. To
> start, our expression will be single line with no assignment.

xbase supports basically what Java supports, plus you can have
additional operators and bind them to any Java type. E.g. have
mathmatical operators for BigDecimal is no problem.

> 2. Generate Java code that is inlined in EMF-generated EOperation
> method bodies

Supported. Xcore does the same.

> 3. Scope and types are custom and mapped to fixed JVM elements at code
> generation. ** In-scope variables are custom-typed and come from
> several configuration sources and map to different JVM elements
> depending on type (based on the STEM API)
> ** In-scope functions provided by plug-ins via extension registry and
> map to static methods

As long as you have a java representation for your types and functions
everything is relatiely easy. Writing code against something which is
not defined in Java, is a bit more compilcated but still possible.

> 5. Provide editor w/content assist, validation, etc

Sure.

> It seems like Xbase is a good place to start. Our question is whether
> Xbase is appropriate, or if we should just start with our own grammar.

Yes, Xbase seems to be a very good fit for your requirements.

Sven


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Xtext/Xbase for writing complex math expressions [message #989296 is a reply to message #989081] Wed, 05 December 2012 09:51 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1761
Registered: July 2009
Senior Member
Am 12/4/12 4:00 PM, schrieb Martin Baker:
>> Write complex math expressions w/variables and function calls.
>
> The following are just a few random thoughts of my own since I am also
> interested in using xtext for mathematics, hopefully someone more
> knowledgeable than me will reply to your message.
>
> It seems to me that it is quite difficult to write mathematical
> expressions in plain text if they contain stuff like: Integrals,
> summations, complicated denominator, matrix, vector, suffix, superscript
> and so on. It would be much more readable if these things could be coded
> in MathML (that is: XML). I've often thought that it would be good if
> the xtext grammar could optionally be replaced with something like an
> XML schema but all the other features on xtext like UI editor, code
> generation, scoping and so on could be retained? The language would need
> to define how each element is displayed.

Isn't XML still text?

> I wonder if Scala-style Case Classes would help with decomposing
> expressions. It would help even more if this pattern matching capability
> could be extended to work across algebra types (integer, real(double),
> complex, vector, matrix and so on). The point being that, in algebra
> types like this, operations like '+' and '*' are heavily overloaded and
> there are cross-cut issues between expressions and algebra types.
>
> I find it messy converting expressions to object oriented form, I know
> that xtend/xbase allows e1+e2 to be coded as e1.operator_plus(e2), for
> example, but I still find it messy. For instance if we want to support
> float * matrix and also matrix * float do we have to modify both the
> float and matrix classes?

No you can define them externally as extension methods.

Sven

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Xtext/Xbase for writing complex math expressions [message #989325 is a reply to message #988925] Wed, 05 December 2012 11:17 Go to previous message
Martin Baker is currently offline Martin Baker
Messages: 31
Registered: July 2009
Member
> Isn't XML still text?

True, but I would like both the editor and syntax analysis to operate at a higher level.

In terms of the editor I would like a WYSIWYG graphical equation editor.

Then, since the equations are coded in XML tags, why not also encode the program structure in tags also. Like this:

<if> <predicate> ... </predicate> <statement> ... </statement></if>

I suspect integrating a graphical editor into xtext would be too hard for me to do, but I would really like to do this if it was not so hard.

Martin
Previous Topic:xtext injected parser
Next Topic:[CDO/XText int
Goto Forum:
  


Current Time: Sat Aug 30 16:43:05 EDT 2014

Powered by FUDForum. Page generated in 0.07814 seconds