This is how it can be done using Xtext and openArchitectureWare.
1) Download the oAW distro from itemis
2) Create a new Xtext Project
3) Paste the following Xtext grammar into the opened editor:
Statemachine :
'events'
(events+=Event)*
'end'
'commands'
(commands+=Command)*
'end'
(states+=State)*;
Event :
(resetting?='resetting')? name=ID code=ID;
Command :
name=ID code=ID;
State :
'state' name=ID
('actions' '{' (actions+=[Command])+ '}')?
(transitions+=Transition)*
'end';
Transition :
event=[Event] '=>' state=[State];
4) start the generator (right click on generate.oaw Run->oaw workflow)
your're done.
You not only get an Antlr based parser but also get an EMF based AST (SemanticModel), and a fully fledged eclipse editor.
Of course it's up to you whether you want to interpret models or generate some code out of them. I choosed to write a small Xpand template file, generating a "controller".
Here it is.
Hi Sven,
ReplyDeletenow I have test the sample with Antlr and with xText and will say, xText is cool and much easier!!! ;)
Regards,
Markus
Sven,
ReplyDeleteThank you for your clear and crisp example! It helps me tremendously to explain the concepts of MDSD, in particular the DSL. The major challenge, at least in my opinion, is coming up with a suitable DSL. The more examples, the easier it will become.
Cheers,
Frank