Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to select an event from numerous events
How to select an event from numerous events [message #1793990] Wed, 22 August 2018 04:04 Go to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
I have numerous events in my code and I wish to handle them separately. For Example:

event z
event z_next
event led
event led_next
event delay_count

Those are my events and I wish to select just the second event from my code generator. How do I proceed? I have tried this:

«FOR s:machine.events»
«s.name»
«ENDFOR»

The above loop helped me to list all the events. But I wish to just select one of them.

I have the same problem with my Transitions. These are my Transitions:

z <= z_next
delay_count <= delay_count
z_next <= Verschlussstand
z_next <= Fill
z <= warte
z_next <= ID_Test
z_next <= Error
z_next <= Kaffee
z_next <= Latte
z_next <= Reinigen
z_next <= warte

I wish to do same for my transitions. I have uploaded a screenshot of my grammar. Thanks for helping.
  • Attachment: ga.PNG
    (Size: 17.57KB, Downloaded 16 times)
Re: How to select an event from numerous events [message #1793992 is a reply to message #1793990] Wed, 22 August 2018 04:54 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
How would you do it in Java?

Why use a for loop and not

Statemachine.events.get(1)

It's really hard to follow you cause you don't explain what you want to achieve in the first place. Why do you need
The second event. What do you try to achieve


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 22 August 2018 04:57]

Report message to a moderator

Re: How to select an event from numerous events [message #1793993 is a reply to message #1793992] Wed, 22 August 2018 05:11 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
I am trying to describe a statemachine written in vhdl. At the level of the codegenerator i wanted to be able to handle every event separately. Yeah ofcourse I tired
Machine.events.get(i) but it did not work. Same for Transitions:
I tried machine.transitions.get(i) but still did not work.
My first event is z.
My wish is to be able to have just z when I do this:
Machine.events.get(0). I hope you could follow me better now. Thanks in advance for your support.
Re: How to select an event from numerous events [message #1793997 is a reply to message #1793993] Wed, 22 August 2018 06:35 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
please post complete grammar, complete sample model , complete generator, unit test with expected output

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1793998 is a reply to message #1793997] Wed, 22 August 2018 06:38 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
Ok. I will do that this evening as soon as Im home. Thanks for your concern.
Re: How to select an event from numerous events [message #1794002 is a reply to message #1793998] Wed, 22 August 2018 08:02 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 236
Registered: June 2013
Senior Member
IIRC, there were some ecore utilities used in the Greetings example generator.
This way you can navigate/filter/scan your AST as you like it.
Re: How to select an event from numerous events [message #1794003 is a reply to message #1794002] Wed, 22 August 2018 08:04 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
Please can you post the link of the Greetings example you are talking about? Thanks
Re: How to select an event from numerous events [message #1794011 is a reply to message #1794003] Wed, 22 August 2018 10:24 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 236
Registered: June 2013
Senior Member
whenever you create a new xtext project, you get some initial coding for grammar and generator.
These are named the "Greetings" example which is often used as a satndardised base for testcases
Re: How to select an event from numerous events [message #1794031 is a reply to message #1793997] Wed, 22 August 2018 17:15 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
I have just uploaded all necessary files for you to have an overview of what I am doing right now, Thanks so much for your help.
Re: How to select an event from numerous events [message #1794032 is a reply to message #1794031] Wed, 22 August 2018 17:30 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
No PNGs want to copy and paste

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1794033 is a reply to message #1794032] Wed, 22 August 2018 17:45 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
I have uploaded the Grammar, Codegenerator and Eclipse App(code.vhdl). I hope thats all you need. I want my codegenerator to produce this:


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;



entity m_Kaffeemaschine is
Port ( Fuellstand : in STD_LOGIC;
Verschluss : in STD_LOGIC;
Start : in STD_LOGIC;
Pad_ID : in STD_LOGIC_VECTOR (1 downto 0);
clk : in STD_LOGIC;
reset : in STD_LOGIC;
led_enable : in STD_LOGIC;
LED_out : out STD_LOGIC_VECTOR (2 downto 0));
end m_Kaffeemaschine;

architecture Behavioral of m_Kaffeemaschine is


type zustand is (warte, Verschlussstand, ID_Test, Reinigen, Kaffee, Latte, Error, Fill);


signal z, z_next : zustand := warte;


signal led, led_next : STD_LOGIC_VECTOR(2 downto 0) := (others => '0');


signal delay_count : INTEGER range 0 to 59999 := 0;

z <= z_next
delay_count <= delay_count
z_next <= Verschlussstand
z_next <= Fill
z <= warte

[Updated on: Wed, 22 August 2018 17:48]

Report message to a moderator

Re: How to select an event from numerous events [message #1794034 is a reply to message #1794033] Wed, 22 August 2018 17:55 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
sample model is still missing

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1794035 is a reply to message #1794034] Wed, 22 August 2018 18:04 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
Do you mean this?
Re: How to select an event from numerous events [message #1794036 is a reply to message #1794035] Wed, 22 August 2018 18:04 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
no i mean the app. the input for the generator

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1794037 is a reply to message #1794036] Wed, 22 August 2018 18:09 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
Here!!!
Re: How to select an event from numerous events [message #1794039 is a reply to message #1794033] Wed, 22 August 2018 18:16 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
Hi,

first of all your current dsl and the target are very diffent from each other.
thus you need to do all that .get(x) cause you currently dont know about the parameter types etc and need to hardcode that.
i am not sure if this modus operandi is good or if you should first focus on enhancing your dsl and then starting generation

here is some snippet for your transitions (they suffer from a bad grammar too)

class MyDslGenerator extends AbstractGenerator {

override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
		resource.allContents.filter(typeof(Statemachine)).forEach[it.generateMachine(fsa)]
	}
	
	def void generateMachine(Statemachine machine, IFileSystemAccess2 fsa){
		
		fsa.generateFile(machine.name+".vhdl",machine.generate)
		
	}
	
	def CharSequence generate(Statemachine machine)
		
	
		'''
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
		
entity «machine.name» is
	Port(
	// TODO why is this list hardcoded
	   «machine.ports.head.names.get(0)» : in  STD_LOGIC;
	   «machine.ports.head.names.get(1)» : in  STD_LOGIC;
       «machine.ports.head.names.get(2)» : in  STD_LOGIC;
       «machine.ports.head.names.get(3)» : in  STD_LOGIC;
       «machine.ports.head.names.get(4)» : in  STD_LOGIC_VECTOR (1 downto 0);
       «machine.ports.head.names.get(5)» : in  STD_LOGIC;
       «machine.ports.head.names.get(6)» : in  STD_LOGIC;
	   «machine.ports.head.names.get(7)» : out  STD_LOGIC_VECTOR (2 downto 0));
	end «machine.name»;

architecture Behavioral of «machine.name» is



type zustand is («FOR s:machine.states SEPARATOR ","» «s.name»«ENDFOR»)


// TODO why are these 3 hardcoded
signal «machine.events.get(0).name», «machine.events.get(1).name» : zustand := «machine.states.get(1).name»;


signal «machine.events.get(2).name», «machine.events.get(3).name» : STD_LOGIC_VECTOR(2 downto 0) := (others => '0');


signal «machine.events.get(4).name» : INTEGER range 0 to 59999 := 0; 	

«FOR transition : machine.transitions»
	«IF transition.event !== null»
		«IF transition.target instanceof State»
			««« your grammar is bad here better introduce a common supertype like "Thingy:State|Event;" and use "target=[Thingy]"
			«transition.event.name» <= «(transition.target as State).name»
		«ENDIF»
	«ELSE»
		// TODO what to generate hene
	«ENDIF»
«ENDFOR»	
		'''
}




Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1794040 is a reply to message #1794039] Wed, 22 August 2018 18:27 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
I am so greatful for your constructive comments. As I said in the beginning I am very new to dsl, xtext..... I will use your interesting comments and try my best. Naturally I will then give you a feedback. Thanks Thanks alot Mr Dietrich.
Re: How to select an event from numerous events [message #1794041 is a reply to message #1794040] Wed, 22 August 2018 18:45 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
One last question for today. If the transitions are separated lets say:

signal delay_count : INTEGER range 0 to 59999 := 0;
z <= z_next
if reset = '1' then
z <= warte


Will it still be possible to get the transitions using a FOR Loop? No I dont think so.
I this case,

my first event acording to my sample model is "z <= z_next" -->can I try this here : «machine.transitions.get(0)» ??
my foufth event will be "z <= warte" «machine.transitions.get(4)» ??

Is that possible?
Re: How to select an event from numerous events [message #1794042 is a reply to message #1794041] Wed, 22 August 2018 19:07 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
i dont understand your domain.
thus i cannot follow you

z <= z_next

is a transition, not a event


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1794044 is a reply to message #1794042] Wed, 22 August 2018 19:23 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
I want to select just the second Transition. Since the compiler starts counting from zero. Can I do this?

machine.transitions,get(1)
Re: How to select an event from numerous events [message #1794045 is a reply to message #1794044] Wed, 22 August 2018 19:32 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
machines.transitions.get(1)

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1794046 is a reply to message #1794045] Wed, 22 August 2018 19:43 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
machines.transitions.get(1) --> org.xtext.kaffeemaschine.statemachine.impl.TransitionImpl@14aa84f
seems not to work.
Re: How to select an event from numerous events [message #1794047 is a reply to message #1794046] Wed, 22 August 2018 19:46 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
machines.transitions.get(1) gives you an object of type transition (the impl call is transitionimpl)
=> you need to actually examine the contents event/target as i do it

«IF transition.event !== null»
«IF transition.target instanceof State»
««« your grammar is bad here better introduce a common supertype like "Thingy:State|Event;" and use "target=[Thingy]"
«transition.event.name» <= «(transition.target as State).name»
«ENDIF»
«ELSE»
// TODO what to generate hene
«ENDIF»


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1794052 is a reply to message #1794047] Thu, 23 August 2018 03:14 Go to previous messageGo to next message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
Is it possible to select just one transition? I have tried everything possible. Nothing is working. Help please
Re: How to select an event from numerous events [message #1794058 is a reply to message #1794052] Thu, 23 August 2018 04:23 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
I still don't understand

machine.transitions.get(1)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1794059 is a reply to message #1794058] Thu, 23 August 2018 05:13 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12252
Registered: July 2009
Senior Member
maybe you did not get that xtend is a GPL and your should use the same concepts as you would use in java (e.g. separation into methods

class MyDslGenerator extends AbstractGenerator {

	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
		resource.allContents.filter(typeof(Statemachine)).forEach[it.generateMachine(fsa)]
	}

	def void generateMachine(Statemachine machine, IFileSystemAccess2 fsa) {

		fsa.generateFile(machine.name + ".vhdl", machine.generate)

	}

	def CharSequence generate(Statemachine machine) '''
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
		
entity «machine.name» is
	Port(
	// TODO why is this list hardcoded
	   «machine.ports.head.names.get(0)» : in  STD_LOGIC;
	   «machine.ports.head.names.get(1)» : in  STD_LOGIC;
       «machine.ports.head.names.get(2)» : in  STD_LOGIC;
       «machine.ports.head.names.get(3)» : in  STD_LOGIC;
       «machine.ports.head.names.get(4)» : in  STD_LOGIC_VECTOR (1 downto 0);
       «machine.ports.head.names.get(5)» : in  STD_LOGIC;
       «machine.ports.head.names.get(6)» : in  STD_LOGIC;
	   «machine.ports.head.names.get(7)» : out  STD_LOGIC_VECTOR (2 downto 0));
	end «machine.name»;

architecture Behavioral of «machine.name» is



type zustand is («FOR s : machine.states SEPARATOR ","» «s.name»«ENDFOR»)


// TODO why are these 3 hardcoded
signal «machine.events.get(0).name», «machine.events.get(1).name» : zustand := «machine.states.get(1).name»;


signal «machine.events.get(2).name», «machine.events.get(3).name» : STD_LOGIC_VECTOR(2 downto 0) := (others => '0');


signal «machine.events.get(4).name» : INTEGER range 0 to 59999 := 0; 	

«FOR transition : machine.transitions»
	«transition.doSomethingWithATransition»
«ENDFOR»

//here is your special second transition thing
«machine.transitions.get(1).doSomethingWithATransition»	
		'''
	
	def doSomethingWithATransition(Transition transition) {
		'''
		«IF transition.event !== null»
			«IF transition.target instanceof State»
				««« your grammar is bad here better introduce a common supertype like "Thingy:State|Event;" and use "target=[Thingy]"
				«transition.event.name» <= «(transition.target as State).name»
			«ENDIF»
		«ELSE»
			// TODO what to generate hene
		«ENDIF»
		'''
	}

}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to select an event from numerous events [message #1794088 is a reply to message #1794059] Thu, 23 August 2018 10:26 Go to previous message
Stevo McLaren is currently offline Stevo McLarenFriend
Messages: 26
Registered: July 2018
Junior Member
Thanks for your support Mr. Dietrich. I will apply all the changes and will give you a feedback. Thanks again.
Previous Topic:Acces a single element in a list of events
Next Topic:ProposalProvider functionality at the web editor
Goto Forum:
  


Current Time: Wed Sep 26 12:51:53 GMT 2018

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

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

Back to the top