Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » call interpreter
call interpreter [message #734979] Mon, 10 October 2011 14:55 Go to next message
samir  is currently offline samir Friend
Messages: 27
Registered: September 2011
Junior Member
hello
after creating my language
I have a doubt:
Where do I enter the interpreter code?
Re: call interpreter [message #734981 is a reply to message #734979] Mon, 10 October 2011 15:02 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You write it as a plugin :)

- load the model
- iterate and evaluate
- etc.

The polymorphic dispatch support in Xtext is very suitable for writing
an evaluator. I am sure there are several examples to look at. I wrote
one for Eclipse/b3.

Do you want to run things in the IDE, or on the command line?
(Running things that are also potentially being edited is slightly more
tricky).

- henrik

On 10/10/11 4:55 PM, samir wrote:
> hello
> after creating my language
> I have a doubt:
> Where do I enter the interpreter code?
Re: call interpreter [message #735006 is a reply to message #734981] Mon, 10 October 2011 15:58 Go to previous messageGo to next message
samir  is currently offline samir Friend
Messages: 27
Registered: September 2011
Junior Member
I want to run from the IDE
Where can I find examples?
Re: call interpreter [message #735024 is a reply to message #735006] Mon, 10 October 2011 16:51 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 10/10/11 5:58 PM, samir wrote:
> I want to run from the IDE
> Where can I find examples?

You find all of Eclipse/b3 in it's git repository at eclipse. (It is at
github as well. https://github.com/eclipse/b3).

The core evaluator is here:
https://github.com/eclipse/b3/blob/master/org.eclipse.b3.backend/src/org/eclipse/b3/backend/evaluator/B3BackendEvaluator.java

You will find different polyporphic methods for calls and evaluation.
Here is an example:

public Object evaluate(BOrExpression o, BExecutionContext ctx) throws
Throwable {
if(Boolean.TRUE.equals(doEvaluate(o.getLeftExpr(), ctx)))
return Boolean.TRUE;
return doEvaluate(o.getRightExpr(), ctx);
}

The BExecutionContext provides access to the execution stack (among
other things). Exactly how b3 does this is probably not of much value to
you, but you may find it useful to look at some things are done.

In
https://github.com/eclipse/b3/tree/master/org.eclipse.b3.build.ui/src/org/eclipse/b3/build/ui/commands
there are several different ways shown how to run things from within the
IDE using a wizards (ask user for some values that are injected into the
evaluation of the DSL), etc. This includes popping dialogs with the
result, output to console etc. Again, this is not written to be intended
as some framework for others to use, but you may find useful things, and
may save you some time vs. figuring everything out from scratch.

Regards
- henrik
Previous Topic:Opposite references not working
Next Topic:resolve cross-reference during creating EObjectDescription
Goto Forum:
  


Current Time: Fri Apr 26 09:33:32 GMT 2024

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

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

Back to the top