Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » implicit variable declaration in dsl editor with xbase
implicit variable declaration in dsl editor with xbase [message #1060462] Fri, 24 May 2013 20:14 Go to next message
andrea rossi is currently offline andrea rossiFriend
Messages: 23
Registered: April 2013
Junior Member
Hi , this is a part of my dsl grammar :
.....
ReceiveMessage returns xbase::XExpression : 
  {ReceiveMessage} 'receive message' name=ValidID 'do' body= XBlockExpression
;

Message returns xbase::XExpression: 
	SendMessage | ReceiveMessage
;

XExpressionInsideBlock returns xbase::XExpression:
	XVariableDeclaration | XExpression | Message;
....



In my dsl editor i can write this :
...
behaviour HelloBehaviour is CyclicBehaviour 
{ receive message msg 
  do {
	val i = 5
        msg.getContent() // error no declaration of msg 
     }
}	


I can't write msg.getContent() in the receive message body because i haven't declare msg.
I would like to write "receive message msg" in dsl editor and can use msg like a variable in the body of receive message.
(e.g implicit declaration : ACLMessage msg )
How can i do it?

Thank you...

[Updated on: Sat, 25 May 2013 23:06]

Report message to a moderator

Re: implicit variable declaration in dsl editor with xbase [message #1060528 is a reply to message #1060462] Sun, 26 May 2013 09:02 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 05/24/2013 10:14 PM, andrea rossi wrote:
> Hi , this is a part of my dsl grammar :
> ....
> ReceiveMessage returns xbase::XExpression : {ReceiveMessage} 'receive
> message' name=ValidID 'do' body= XBlockExpression
> ;
>
> Message returns xbase::XExpression: SendMessage | ReceiveMessage
> ;
>
> XExpressionInsideBlock returns xbase::XExpression:
> XVariableDeclaration | XExpression | Message;
> ...
>
>
>
> In my dsl editor i can write this :
> ..
> behaviour HelloBehaviour is CyclicBehaviour { receive message msg do {
> val i = 5
> msg.getContent() // error no declaration of msg }
> }
>
>
> I can't write msg.getContent() in the receive message body because i
> haven't declare msg.
> I would like can write "receive message msg" in dsl editor and can use
> msg like a variable in the body of receive message.
> (e.g implicit declaration : ACLMessage msg )
>

you should write the JvmModelInferrer accordingly, e.g., for receive
message (by the way, do not use terminal symbols with spaces: 'receive'
'message', instead of 'receive message') you can infer a method with
parameter 'msg' and with the appropriate type, and the the XExpression
after 'do' can access msg (once you associated the XExpression to the
body of the inferred method).

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it


Re: implicit variable declaration in dsl editor with xbase [message #1060598 is a reply to message #1060528] Mon, 27 May 2013 08:55 Go to previous messageGo to next message
andrea rossi is currently offline andrea rossiFriend
Messages: 23
Registered: April 2013
Junior Member
Thank you for your advices...

I don't use JvmModelInferrer for receive message but extend XBaseCompiler
This is a part of my class that extend XbaseCompiler :


override protected doInternalToJavaStatement(XExpression expr, ITreeAppendable it, boolean isReferenced) {

.....

switch expr {

ReceiveMessage : {
			
			if (expr.filter != null){
				newLine
		    	append ('''MessageTemplate mt = null; ''')
  				newLine 
  				append ('''mt = ''' )
  				append('''«createTemplate(expr.filter as Expression,it)» ;''')
				newLine 
				append('''
					jade.lang.acl.ACLMessage msg = myAgent.receive(mt); ''')	
			}
			else {  newLine append('''jade.lang.acl.ACLMessage msg = myAgent.receive()''')}
			newLine 
			append('''if (msg!=null){ ''')
			increaseIndentation()
			doInternalToJavaStatement(expr.body, it, isReferenced) 
			append('''} ''') 
			decreaseIndentation()
			newLine 
			append('''else { block(); }''')		
			
		}

....




I call doInternalToJavaStatement method and pass ReceiveMessage body.
How i can set implicit variable declaration here?


thank you in advance

[Updated on: Mon, 27 May 2013 08:59]

Report message to a moderator

Re: implicit variable declaration in dsl editor with xbase [message #1060628 is a reply to message #1060598] Mon, 27 May 2013 11:31 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Try to use JvmModelInferrer whenever possible since you'll get for free
correct scoping!

You can have a customized XbaseCompiler to deal with your custom
XExpression (if you have any) or invoke XbaseCompiler directly if you
want to generate code before and after the actual XExpression's
translation... but for the rest, try to use JvmModelInferrer

I don't know whether this http://www.rcp-vision.com/?p=4089 might help you

Lore

On 05/27/2013 10:55 AM, andrea rossi wrote:
> Thank you for you advices...
> I don't use JvmModelInferrer for receive message but extend XBaseCompiler
> This is a part of my class that extend XbaseCompiler :
>
>
>
> override protected doInternalToJavaStatement(XExpression expr,
> ITreeAppendable it, boolean isReferenced) {
>
> ....
>
> switch expr {
>
> ReceiveMessage : {
>
> if (expr.filter != null){
> newLine
> append ('''MessageTemplate mt = null; ''')
> newLine append ('''mt = ''' )
> append('''«createTemplate(expr.filter as
> Expression,it)» ;''')
> newLine append('''
> jade.lang.acl.ACLMessage msg = myAgent.receive(mt);
> ''')
> }
> else { newLine append('''jade.lang.acl.ACLMessage msg =
> myAgent.receive()''')}
> newLine append('''if (msg!=null){ ''')
> increaseIndentation()
> doInternalToJavaStatement(expr.body, it, isReferenced)
> append('''} ''') decreaseIndentation()
> newLine append('''else { block(); }''')
>
> }
>
> ...
>
>
>
>
> I call doInternalToJavaStatement method and pass ReceiveMessage body.
> How can set implicit variable declaration here?
>
>
> thank you in advance
>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it


Re: implicit variable declaration in dsl editor with xbase [message #1061091 is a reply to message #1060628] Wed, 29 May 2013 21:06 Go to previous messageGo to next message
andrea rossi is currently offline andrea rossiFriend
Messages: 23
Registered: April 2013
Junior Member
Thank you ,

I read the link but i can't solve my problem..
ReceiveMessage is a xbase Expression and i need to extend XbaseCompiler to manage it.

is There another way to solve this problem?any suggestions?

thank you in advance

[Updated on: Wed, 29 May 2013 21:19]

Report message to a moderator

Re: implicit variable declaration in dsl editor with xbase [message #1061096 is a reply to message #1061091] Wed, 29 May 2013 21:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi what about Fixing the scoping Manually

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implicit variable declaration in dsl editor with xbase [message #1061133 is a reply to message #1061091] Thu, 30 May 2013 07:41 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 05/29/2013 11:06 PM, andrea rossi wrote:
> Thank you ,
>
> I read the link but i can't solve my problem..
> ReceiveMessage is a xbase Expression and i need to extend XbaseCompiler
> to manage it.
>
> is There another way to solve this problem?any suggestions?

You actually need to extend XbaseCompiler to deal with your custom
XExpression (i.e., ReceiveMessage); what I'm saying is that if you map
that concept to a Java model method and the 'msg' to a parameter then
the body, when associated to the mapped method, will automatically get a
working scope...

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it


Re: implicit variable declaration in dsl editor with xbase [message #1061485 is a reply to message #1061133] Fri, 31 May 2013 21:22 Go to previous messageGo to next message
andrea rossi is currently offline andrea rossiFriend
Messages: 23
Registered: April 2013
Junior Member
Hi,

this i part of my JvmModelInferrer :
def dispatch void infer(Model element, 
                IJvmDeclaredTypeAcceptor acceptor, 
                boolean isPrelinkingPhase) {
    
    
    for (a : element.elements) {
    	switch a {
    		AbstractBehaviour : {
    			switch a {
    				SimpleBehaviour : {
    					  acceptor.accept(a.toClass(a.fullyQualifiedName)).initializeLater [
    						superTypes += a.newTypeRef('jade.core.behaviours.'+ a.typeSB.toString)
    						members += a.toConstructor[
    							documentation = '''...'''
    							parameters += toParameter("agent", newTypeRef(a, 'jade.core.Agent'))
    							body = [
      									append('''
        								super(agent);
      									''')
    							]
  							]
    						members += a.toMethod("action",a.newTypeRef(Void::TYPE))[
    						body = a.body
    						]
    					]
    					
    				}
    			}
    		}




i translate each simpleBehaviour in a java class e i inferr one method(action).
The body of this method is body of behaviour(i.e XblockExpression) and it can contain xbase expression or my custom xbase expression.

How can i map ReceviMessage in the right way?(it must been contained in the action body)
any little example?


Hi Christian how can i fix the scoping of my custom xbase expression?

thank you
Re: implicit variable declaration in dsl editor with xbase [message #1061489 is a reply to message #1061485] Fri, 31 May 2013 22:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Sorry you have to digg into scoping yourself

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implicit variable declaration in dsl editor with xbase [message #1061499 is a reply to message #1061485] Sat, 01 June 2013 07:40 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
ReceiveMessage returns xbase::XExpression : {ReceiveMessage} 'receive
message' name=ValidID 'do' body= XBlockExpression

I would map it as follows

ReceiveMessage -> Java method
name -> Java method's parameter (you have to give it a type)
body -> Java method's body

this way

receive message msg do {
val i = 5
msg.getContent() // error no declaration of msg }
}

msg can be automatically accessed...

of course I do not know all the details and semantics of your language,
so mine's just a guess...

Lorenzo

On 05/31/2013 11:22 PM, andrea rossi wrote:
> Hi,
>
> this i part of my JvmModelInferrer :
> def dispatch void infer(Model element,
> IJvmDeclaredTypeAcceptor acceptor, boolean
> isPrelinkingPhase) {
> for (a : element.elements) {
> switch a {
> AbstractBehaviour : {
> switch a {
> SimpleBehaviour : {
>
> acceptor.accept(a.toClass(a.fullyQualifiedName)).initializeLater [
> superTypes +=
> a.newTypeRef('jade.core.behaviours.'+ a.typeSB.toString)
> members += a.toConstructor[
> documentation = '''...'''
> parameters += toParameter("agent",
> newTypeRef(a, 'jade.core.Agent'))
> body = [
> append('''
> super(agent);
> ''')
> ]
> ]
> members +=
> a.toMethod("action",a.newTypeRef(Void::TYPE))[
> body = a.body
> ]
> ]
>
> }
> }
> }
>
>
>
>
> i translate each simpleBehaviour in a java class e i inferr one
> method(action).
> The body of this method is body of behaviour(i.e XblockExpression) and
> it can contain xbase expression or my custom xbase expression.
>
> How can i map ReceviMessage in the right way?(it must been contained in
> the action body)
> any little example?
>
>
> Hi Christian how can i fix the scoping of my custom xbase expression?
> thank you


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it


Previous Topic:Nested comments
Next Topic:Problem with unresolved classpath proxy URIs after upgrading to 2.4.2
Goto Forum:
  


Current Time: Thu Mar 28 20:01:33 GMT 2024

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

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

Back to the top