Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to start (Attach a specific semantic to my grammar)
How to start [message #1386074] Fri, 13 June 2014 10:45 Go to next message
Félix SILINOU KAMDEM is currently offline Félix SILINOU KAMDEMFriend
Messages: 96
Registered: April 2013
Member
Hello everyone, I have create this grammar:
/***   Alternatives ****/
Alternative 1:
    for {e1, e2, e3} select :
    R1 or R2 or R3;

Alternative 2:
    for {e6, e7, e8} select :
    R6 or R7 or R8;



/***   Decision appears when the user make a choice from [b][i]alternative i[/i][/b], [b][i]alternative i[/i][/b] will be automatically delete from the file ****/
Decision 1 select R7 for {e6, e7, e8} :
    consequences : decision 1.0 select R2 for {e1, e2, e3} and exclude R7 for {e6,e7,e8}



/***   Tell if the rule has to be excluded or Apply when the decision is validate. Automatically, Decision will be delete from the file ****/
Exclude rule R10 for {e9};
Apply rule R12 for {e10,e11};


What I want to do is this :
1 - I have a file which contains only some Alternatives.
2 - An user has a possibility to make a choise from an Alternative
3 - Decision appears when the user make a choice from Alternative i, Alternative i will be automatically delete from the file
4 - Tell if the rule has to be exclude or Apply when the Decision is validate. Automatically, the Decision will be delete from the file

The problem is that, I don't know howI can do that.

Thank you in advance for your help.

[Updated on: Fri, 13 June 2014 10:46]

Report message to a moderator

Re: How to start [message #1386131 is a reply to message #1386074] Fri, 13 June 2014 14:21 Go to previous messageGo to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
I really struggled to get started with Xtext and Xtend (I did this about 8 months ago, finally succeeded, then stopped until this week). So I'm not an expert. But, for me anyway, it's a lot easier to try to figure out what you want to do if you give a simple, concrete example of your input file and output file contents along with the description you have given above.
Re: How to start [message #1386616 is a reply to message #1386131] Wed, 18 June 2014 17:46 Go to previous messageGo to next message
Félix SILINOU KAMDEM is currently offline Félix SILINOU KAMDEMFriend
Messages: 96
Registered: April 2013
Member
Hi @Gary,

Can I have a link for the tutorial you used to learn Xtext and Xtend.

Regards,
Felix
Re: How to start [message #1386678 is a reply to message #1386616] Thu, 19 June 2014 12:14 Go to previous messageGo to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
Of course I used the main Xtext pages: http://www.eclipse.org/Xtext/
Lars Vogel has some good tutorials; this one is about EMF rather than Xtext explicitly. http://www.vogella.com/tutorials/EclipseEMF/article.html

I looked at your example, not sure I really understand it. I can tell you what I did and see if it helps you understand at least MY application of Xtext and Xtend.

My existing problem was that I was writing (still am) a DSP CAD program using Java Swing. I am using a library that some other guy wrote, which models the instruction set of the DSP chip, but does so in Java so that you can do object-oriented things with code blocks. This is exactly the approach that I used in my CAD program.

I got tired of hand translating existing DSP code to Java, so the first thing I used Xtext/Xtend for was to generate the proper Java code and methods (specific to my program) from a slightly annotated DSP code file. Suddenly, tasks that had taken hours took minutes, with much less debugging involved.

Then I saw that a lot of the coding I was doing in Java to determine information about the DSP model I was building with code blocks also had repetitive patterns. These patterns were conceptually simple but tedious to code in Java. So I abstracted those Java code patterns into a more concise syntax. Again, a great increase in development speed and great decrease in bugs.

Finally, I developed a bunch of Swing "control panels" for each block, with sliders, checkboxes, and radio buttons, to control some of the internal variables of these blocks. Again, after doing it for awhile I started to see patterns repeating and again realized that the concepts were way easier than the code required to implement those concepts. So I am currently adding syntax to my grammar, and expanding my code generators so that I can create vast amounts of instantly functional Java Swing code with just a few statements within my annotated DSP source.

This relies heavily on the "Template" code generation approach you can do with Xtext and Xtend. I didn't accomplish anything that I couldn't have accomplished with Java itself. I saw a way to multiply my productivity by reducing repetitive coding patterns to a much simpler representation. That is the only approach I've used with these tools and it works quite well.

Your example shows alternatives and talks about interaction with the user. So I presume that you have a program written in some language and you are trying to come up with a more compact and repeatable way to represent this. If that's true, it would help to see some of that code applied to a simple example of the type you're trying to solve.

Xtext analyzes your source code according to rules you created and builds a model from this, using all the information you supplied. The Xtend code generator walks through this model (multiple times, if needed) and based on the extracted model details, spits out "Template" code. Nothing in Xtend itself guarantees that this code works properly. It's simply quoted with insertions/substitutions based on the model. The logic of the problem you're solving is contained in this quoted template code, along with the structure contained in the code generator (which you also have to write). The translation from a more compact representation is what Xtext/Xtend offer me. My program still has large sections written in Java that are not going to get replaced with Xtend - there's no benefit to doing this.

Part of my point of view on this is a result of challenges I have designing things up front. I'm not a professional software developer and so I usually do things the hard way for awhile (such a writing Java Swing code directly) before I can see a pattern emerging which could be simplified somehow.

I hope this helps a little!

[Updated on: Thu, 19 June 2014 13:04]

Report message to a moderator

Re: How to start [message #1387134 is a reply to message #1386678] Tue, 24 June 2014 10:42 Go to previous message
Félix SILINOU KAMDEM is currently offline Félix SILINOU KAMDEMFriend
Messages: 96
Registered: April 2013
Member
Thank you very much

[Updated on: Tue, 24 June 2014 10:42]

Report message to a moderator

Previous Topic:Preference page for separate generator
Next Topic:Clean way to call out to external methods?
Goto Forum:
  


Current Time: Mon Aug 03 18:00:21 GMT 2020

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

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

Back to the top