Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using Xtext as a language translator(noob alert)
Using Xtext as a language translator [message #1120593] Sun, 29 September 2013 20:05 Go to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
I have an existing Swing application which I have hand-coded. It is used to develop DSP code for a specific audio-effects targeted DSP chip. Learning the assembler is pretty difficult, especially if you are guitar player who is not also an electrical engineer. I have taken a lot of the hard work out of creating algorithms by coding a handful of them as reusable blocks which users connect together like a flowchart. Here's an example of the display:

http://imageshack.us/a/img836/9517/spincadexample02.png

So here's my problem. Currently I hand code the DSP assembler representation of each block into an equivalent Java representation (which I found as an open-source library, or else I never would have done this at all).

So, for example, the following excerpt in DSP assembler:

RDAX ADCL, 1.0
MULX POT1
WRAX DACL, 0.0

becomes:

ReadRegister(ADCL, 1.0);
Mulx(POT0);
WriteRegister(DACL, 0.0);

So, for the most part, the assembler source contains an instruction followed by 0 to 3 parameters. In two particular cases, the instructions are two tokens separated by a space:

CHO RDAL

maps to ChorusReadDelay().

The capitalized parameters are globally defined constants. Sometimes a parameter will be represented as a logical construct, such as OR'ing or AND'ing some constants together. In all cases, parameters are separated from each other by commas.

Finally, there are comment lines which begin with a semi-colon. I could either ignore these (easiest) or incorporate them somehow, but that's not currently critical.

I've been led to believe that Xtext would be a good way to map the DSP assembler to these Java statements. I've seen and done some examples in Xtext where I saw the model being built on the fly as it parses the correctly formed input.

I just would like to confirm a few things about this approach before I put a lot of effort into it.

#1, as you might imagine, the order of the instructions is important. Will the Xtext model preserve the order?

#2 I don't want to hand type the code in for conversion - I simply want to reference an existing DSP assembler file and have it create the model.

#3 Once the assembler code is converted to Java, I need to make certain substitutions for certain parameter values, and add other bits of Java code which represent the interface to the functionality of my program. How/where do I make that happen? Everything that needs to be done can be determined either through parsing of the assembler file itself, or inferred from attributes in my Ecore model.

#4 The end result I want from this conversion is one Java class per DSP assembler block, within a Java project that represents the source for my Swing application. I also want a menu with a representation of each block (text is OK) that lets you insert said block into the model you are developing.

I have already gone through some examples of EMF, Ecore, etc. with Eclipse and while those things seem to work OK and let me generate a new Eclipse where I could add one of my block definitions from the menu, I'm still lost as to how to read the assembler code from a file (called out by the PATH attribute in an Ecore model) and convert it into Java code.

Any of this make sense?

Anyone able to point me at a similar implementation?

Thanks in advance for any guidance.

GW

[Updated on: Sun, 29 September 2013 20:08]

Report message to a moderator

Re: Using Xtext as a language translator [message #1121162 is a reply to message #1120593] Mon, 30 September 2013 10:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am not sure if i get your usecase.

Xtext helps you to create an AST out of your text file (preserving order). this ast you can use to run an interpreter on it or write a code-generator that creates java or whatever code for you.
i have no idea what you mean with "DST assembler and what you want todo with it"

if i understand the following correct:

(1) you have an assembler file as starting point
(2) you parse it with Xtext and create (code generation) java code out of it.

this works nicely with Xtext


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using Xtext as a language translator [message #1121421 is a reply to message #1121162] Mon, 30 September 2013 15:58 Go to previous messageGo to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
Hi Christian,

For clarity, by "DSP" I meant "digital signal processing" which is the ultimate goal of this code. It has no other relevance to the discussion.

It's possible that my question is more of a general-Eclipse-tool problem. I understand most of how these tools can work and I am trying to describe and/or design the process by which it all magically comes together to minimize hand work.

For example:
1) Xtext can parse and translate an assembler language file (the path of which was an attribute in my Ecore model) to a Java representation.
2) "Something" can analyze the resulting code for input, output, and control "hooks" and generate supporting Java code to handle those.
3) "Something" can analyze the need for GUI (Swing) controls specified in my Ecore model, which would adjust certain variables generated in step 1, and generate the supporting Java code to handle that.
4) "Something" can take the result of steps 2 and 3 and create a new class in my Java project.
5) "Something" can see that there is a new class in my project and add it to the application's menu. The characteristics of this new class are that it extends a specific class in my application and it could also have specific info in the Ecore model which told the "something" which menu heading it belongs under.

Up to now, all of those "somethings" is me, doing it by hand. However it is a predictable, programmable set of steps and so I'm trying to figure out how to get Eclipse to do those things for me.

Thanks,

Gary

[Updated on: Mon, 30 September 2013 16:07]

Report message to a moderator

Re: Using Xtext as a language translator [message #1121494 is a reply to message #1121421] Mon, 30 September 2013 17:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

i still do not see "the problem"
why dont you simply give it a try

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using Xtext as a language translator [message #1121530 is a reply to message #1121494] Mon, 30 September 2013 18:22 Go to previous messageGo to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
I'll take it one step at a time and report back.
Re: Using Xtext as a language translator [message #1159794 is a reply to message #1121530] Mon, 28 October 2013 19:58 Go to previous message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
I just wanted to report back that I have been using Xtext and Xtend for my DSL/code generator and it is working very well! Things that used to take several hours are now reduced to about 5 or 10 minutes. I'm also seeing that (of course) the generated code is much more consistent than what I was writing by hand. As it turns out, using Ecore designer or any of the Ecore-centric tools was not very helpful to me. I really needed to dive right into Xtext and Xtend.

I also struggled for a bit with whether I should combine part of my model, which originates with some digital signal processing assembly code, with an external Ecore model so that the user could access a nice GUI editor to add the parameters to the model as needed. But then I realized that most people who I anticipate being interested in this will be accustomed to using the DSP assembly language and so for them, to add a few more lines to the source file in order to allow all sorts of extra functionality is not so bad. So I extended the DSL (editing the Xtext and Xtend files) beyond just being able to parse the DSP source code and added hooks which create the structure of my Java model.

GW

[Updated on: Mon, 28 October 2013 20:03]

Report message to a moderator

Previous Topic:Xcore as metamodel for Xtext Grammar
Next Topic:Scoping in Xtext
Goto Forum:
  


Current Time: Thu Apr 18 08:52:09 GMT 2024

Powered by FUDForum. Page generated in 0.02400 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top