Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Functions
Functions [message #1804452] Tue, 26 March 2019 07:01 Go to next message
Eclipse UserFriend
Hello,

Anyone know how to create functions, and pass values through them?
Re: Functions [message #1804459 is a reply to message #1804452] Tue, 26 March 2019 07:31 Go to previous messageGo to next message
Eclipse UserFriend
hi, can you please give some more context
Re: Functions [message #1804461 is a reply to message #1804459] Tue, 26 March 2019 07:37 Go to previous messageGo to next message
Eclipse UserFriend
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:
    '\'\'\'' -> '\'\'\'';

[Updated on: Tue, 26 March 2019 07:38] by Moderator

Re: Functions [message #1804466 is a reply to message #1804461] Tue, 26 March 2019 08:24 Go to previous messageGo to next message
Eclipse UserFriend
and what is the problem:

- implement scoping,
- implement validation/typesystem

you are done
Re: Functions [message #1804467 is a reply to message #1804466] Tue, 26 March 2019 08:31 Go to previous messageGo to next message
Eclipse UserFriend
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")


Re: Functions [message #1804470 is a reply to message #1804466] Tue, 26 March 2019 09:12 Go to previous message
Eclipse UserFriend
I found the solution, I forgot that I can access into "superType". Sorry for taking your time.

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


Current Time: Sat Apr 26 08:40:05 EDT 2025

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

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

Back to the top