Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Functions
Functions [message #1804452] Tue, 26 March 2019 11:01 Go to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
Hello,

Anyone know how to create functions, and pass values through them?


noslen
Re: Functions [message #1804459 is a reply to message #1804452] Tue, 26 March 2019 11:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13147
Registered: July 2009
Senior Member
hi, can you please give some more context

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Functions [message #1804461 is a reply to message #1804459] Tue, 26 March 2019 11:37 Go to previous messageGo to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
I want a DSL capable of this:

def name_of_function( var bananas, var potatos) :
   '''
    print(#potatos)
    print(#bananas)
  '''



name_of_function("hello","world")



What I already have done is this:

Dec:
	'def' name=ID  ( '(' args+=Variable (',' args+=Variable)* ')' )? ':' 
	BEGIN
		pythonCode=PYTHONCODE
	END
;

Call:
    superType=[Dec|QualifiedName] (  '(' parm+=Parametrs (',' parm+=Parametrs)*')')? 
;

VariableValue:
	str=STRING |
	var=VariableReference
;


Parametrs:
	value=VariableValue
;

VariableReference:
   '#'ref=[Variable];

Variable:
	
	'var' name=ID ('='  value=STRING)?
;

terminal PYTHONCODE:
    '\'\'\'' -> '\'\'\'';



noslen

[Updated on: Tue, 26 March 2019 11:38]

Report message to a moderator

Re: Functions [message #1804466 is a reply to message #1804461] Tue, 26 March 2019 12:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13147
Registered: July 2009
Senior Member
and what is the problem:

- implement scoping,
- implement validation/typesystem

you are done


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Functions [message #1804467 is a reply to message #1804466] Tue, 26 March 2019 12:31 Go to previous messageGo to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
My problem is to know the name of the variable that is saving the value. Is this possible?

Let's say that in the next example, when I'm calling the "name_of_function" I want to get the name of the variable that will save the value "hello"

def name_of_function( var bananas, var potatos) :
   '''
    print(#potatos)
    print(#bananas)
  '''


name_of_function("hello","world")




noslen
Re: Functions [message #1804470 is a reply to message #1804466] Tue, 26 March 2019 13:12 Go to previous message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
I found the solution, I forgot that I can access into "superType". Sorry for taking your time.

Thanks


noslen
Previous Topic:EByte
Next Topic:Heads-up: Eclipse 2019-03 needs all new project wizards to have an icon
Goto Forum:
  


Current Time: Mon Oct 14 06:26:07 GMT 2019

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

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

Back to the top