Skip to main content



      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 00:04 Go to next message
Eclipse UserFriend
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 105 times)
Re: How to select an event from numerous events [message #1793992 is a reply to message #1793990] Wed, 22 August 2018 00:54 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Wed, 22 August 2018 00:57] by Moderator

Re: How to select an event from numerous events [message #1793993 is a reply to message #1793992] Wed, 22 August 2018 01:11 Go to previous messageGo to next message
Eclipse UserFriend
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 02:35 Go to previous messageGo to next message
Eclipse UserFriend
please post complete grammar, complete sample model , complete generator, unit test with expected output
Re: How to select an event from numerous events [message #1793998 is a reply to message #1793997] Wed, 22 August 2018 02:38 Go to previous messageGo to next message
Eclipse UserFriend
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 04:02 Go to previous messageGo to next message
Eclipse UserFriend
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 04:04 Go to previous messageGo to next message
Eclipse UserFriend
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 06:24 Go to previous messageGo to next message
Eclipse UserFriend
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 13:15 Go to previous messageGo to next message
Eclipse UserFriend
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 13:30 Go to previous messageGo to next message
Eclipse UserFriend
No PNGs want to copy and paste
Re: How to select an event from numerous events [message #1794033 is a reply to message #1794032] Wed, 22 August 2018 13:45 Go to previous messageGo to next message
Eclipse UserFriend
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 13:48] by Moderator

Re: How to select an event from numerous events [message #1794034 is a reply to message #1794033] Wed, 22 August 2018 13:55 Go to previous messageGo to next message
Eclipse UserFriend
sample model is still missing
Re: How to select an event from numerous events [message #1794035 is a reply to message #1794034] Wed, 22 August 2018 14:04 Go to previous messageGo to next message
Eclipse UserFriend
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 14:04 Go to previous messageGo to next message
Eclipse UserFriend
no i mean the app. the input for the generator
Re: How to select an event from numerous events [message #1794037 is a reply to message #1794036] Wed, 22 August 2018 14:09 Go to previous messageGo to next message
Eclipse UserFriend
Here!!!
Re: How to select an event from numerous events [message #1794039 is a reply to message #1794033] Wed, 22 August 2018 14:16 Go to previous messageGo to next message
Eclipse UserFriend
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»	
		'''
}


Re: How to select an event from numerous events [message #1794040 is a reply to message #1794039] Wed, 22 August 2018 14:27 Go to previous messageGo to next message
Eclipse UserFriend
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 14:45 Go to previous messageGo to next message
Eclipse UserFriend
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 15:07 Go to previous messageGo to next message
Eclipse UserFriend
i dont understand your domain.
thus i cannot follow you

z <= z_next

is a transition, not a event
Re: How to select an event from numerous events [message #1794044 is a reply to message #1794042] Wed, 22 August 2018 15:23 Go to previous messageGo to next message
Eclipse UserFriend
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 15:32 Go to previous messageGo to next message
Eclipse UserFriend
machines.transitions.get(1)
Re: How to select an event from numerous events [message #1794046 is a reply to message #1794045] Wed, 22 August 2018 15:43 Go to previous messageGo to next message
Eclipse UserFriend
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 15:46 Go to previous messageGo to next message
Eclipse UserFriend
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»
Re: How to select an event from numerous events [message #1794052 is a reply to message #1794047] Wed, 22 August 2018 23:14 Go to previous messageGo to next message
Eclipse UserFriend
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 00:23 Go to previous messageGo to next message
Eclipse UserFriend
I still don't understand

machine.transitions.get(1)
Re: How to select an event from numerous events [message #1794059 is a reply to message #1794058] Thu, 23 August 2018 01:13 Go to previous messageGo to next message
Eclipse UserFriend
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»
		'''
	}

}
Re: How to select an event from numerous events [message #1794088 is a reply to message #1794059] Thu, 23 August 2018 06:26 Go to previous message
Eclipse UserFriend
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: Sat Jun 14 14:12:28 EDT 2025

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

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

Back to the top