Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Re: Implementing a DSL with Classes, Instances and Function Calls
Re: Implementing a DSL with Classes, Instances and Function Calls [message #552380] Wed, 11 August 2010 23:44 Go to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Christian,

With a newsgroup reader (Thunderbird) you can redirect a post just by
adding the other newsgroup to the reply as I've done here.


Christian Ammann wrote:
> Hi there,
>
> i have a scoping related problem. I Want to implement a DSL which
> contains classes. A class can contain functions. When i instanciate a
> class, i want to call the class functions. Here is a simplified
> example of my DSL:
>
>
> class Stack{ operation push();
> }
>
> Stack s1;
>
> call s1.push();
>
>
> The problem is within the last line: The default scoping only allows
> me something like:
>
> call Stack.push();
>
> My grammar looks like:
>
>
> Model:
> (class+=Class)*
> (vars+=Variable)*
> (calls+=Calls)*
> ;
>
> Variable:
> type=[Class] name=ID ";"
> ;
>
> Class:
> "class" name=ID "{"
> (op+=Operation)*
> "}"
> ;
> Operation:
> "operation" name=ID "(" ")" ";"
> ;
>
> Calls:
> "call" call=[Operation|FQN] "(" ")" ";"
> ;
>
> FQN:
> ID "." ID
> ;
>
>
> I think i have to create somehow my own scope, which uses the instance
> references instead of the class declaration name.
> Thanks for your help in advance,
>
> Christian


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Implementing a DSL with Classes, Instances and Function Calls [message #552434 is a reply to message #552380] Thu, 12 August 2010 09:03 Go to previous messageGo to next message
Christian Ammann is currently offline Christian AmmannFriend
Messages: 21
Registered: July 2010
Junior Member
The original Thread was for thhis forum (Xtext) but i posted it at the wrong place. The Thread can be found here:

http://www.eclipse.org/forums/index.php?t=msg&th=173546& amp;start=0&S=7c4d1a3902e0c5c52ba2a05f549b3017
Re: Implementing a DSL with Classes, Instances and Function Calls [message #552468 is a reply to message #552434] Thu, 12 August 2010 09:38 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

it may make sense to break up the call and adapt scoping

Calls: 'call' variable=[Variable]'.'operation=[Operation]'('')'';';

and adapt scoping so that only operations from the given variable are
visible. You may have to adapt code completion because the default
implementation will try to propose fully qualified names and there is
only one operation in the model (push in Stack whose qualified name is
Stack.push).
I don't know whether further chaining is possible in your case

call s1.pop().chreateHashcode().multiplyByTwo()

In this case it would make sense to think about Expressions and assigned
actions.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Implementing a DSL with Classes, Instances and Function Calls [message #552476 is a reply to message #552468] Thu, 12 August 2010 10:52 Go to previous messageGo to next message
Christian Ammann is currently offline Christian AmmannFriend
Messages: 21
Registered: July 2010
Junior Member
Hi Alex,

thanks for your reply. I had problems understanding the concept of scoping, but your replay together with this this:

http://www.eclipse.org/forums/index.php?t=msg&th=172683& amp;start=0&S=7c4d1a3902e0c5c52ba2a05f549b3017

helped alot. Smile
Re: Implementing a DSL with Classes, Instances and Function Calls [message #630701 is a reply to message #552380] Mon, 04 October 2010 15:34 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
probably this might help: http://fj-eclipse.sourceforge.net/

On 08/12/2010 01:44 AM, Ed Merks wrote:
> Christian Ammann wrote:
>> Hi there,
>>
>> i have a scoping related problem. I Want to implement a DSL which
>> contains classes. A class can contain functions. When i instanciate a
>> class, i want to call the class functions. Here is a simplified
>> example of my DSL:
>>
>>
>> class Stack{ operation push();
>> }
>>
>> Stack s1;
>>
>> call s1.push();
>>
>>
>> The problem is within the last line: The default scoping only allows
>> me something like:
>>
>> call Stack.push();
>>
>> My grammar looks like:
>>
>>
>> Model:
>> (class+=Class)*
>> (vars+=Variable)*
>> (calls+=Calls)*
>> ;
>>
>> Variable:
>> type=[Class] name=ID ";"
>> ;
>>
>> Class:
>> "class" name=ID "{"
>> (op+=Operation)*
>> "}"
>> ;
>> Operation:
>> "operation" name=ID "(" ")" ";"
>> ;
>>
>> Calls:
>> "call" call=[Operation|FQN] "(" ")" ";"
>> ;
>>
>> FQN:
>> ID "." ID
>> ;
>>
>>
>> I think i have to create somehow my own scope, which uses the instance
>> references instead of the class declaration name.
>> Thanks for your help in advance,
>>
>> Christian


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Previous Topic:Keyword-reference collision: backtrackLexer doesn't help
Next Topic:IContentOutlineNodeForTextSelection - what is it supposed to do?
Goto Forum:
  


Current Time: Tue Apr 23 10:12:06 GMT 2024

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

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

Back to the top