Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Interpreter for xtext
Interpreter for xtext [message #1149067] Mon, 21 October 2013 23:09 Go to next message
Caroline Smith is currently offline Caroline SmithFriend
Messages: 7
Registered: October 2013
Junior Member
Hi everybody! I'm using xtext to implement a language, now I have my grammar, but I also want to execute the programs wrote with this, in a few words I need an xtext interpreter, but I can't understand if it's possible to do it using xtext!
Can someone help me? Sad

Thank you! Smile
Re: Interpreter for xtext [message #1149500 is a reply to message #1149067] Tue, 22 October 2013 06:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Hi,

Interpreting is traversing the ast and doing something. If you
generate code the something is producing text.

Where to exactly start depends on how to call the interpreter. Maybe
(if you want to call it from context menu have a look at
http://christiandietrich.wordpress.com/2011/10/15/xtext-calling-the-gen
erator-from-a-context-menu/)

You may have a look at the arithmetics example too

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Interpreter for xtext [message #1149501 is a reply to message #1149067] Tue, 22 October 2013 06:03 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
It's for sure possible.
It depends on the kind of language you have but if it's something
expression like, i.e. something that computes values, the simplest
approach is to traverse the expression tree and passing along the
variable scope.

Typically this would involve a dispatch over the different expression
kinds where you return the results. Example (using Xtend):

def dispatch BigDecimal invoke(Multiplication it, Map<String,Object>
scope) {
invoke(left) * invoke(right)
}

def dispatch BigDecimal invoke(Addition it, Map<String,Object> scope) {
invoke(left) + invoke(right)
}

def dispatch BigDecimal invoke(NumberLiteral it, Map<String,Object> scope) {
value
}

def dispatch BigDecimal invoke(VariableReference it, Map<String,Object>
scope) {
scope.get(it.variableName)
}

Xbase comes with an interpreter. So in case you want to have a look at
something real :
http://grepcode.com/file/repo1.maven.org$maven2@xxxxxxxxe.xtend$org.eclipse.xtend.standalone@2.4.2@org$eclipse$xtext$xbase$interpreter$impl$XbaseInterpreter.java

Here the _doEvaluate method corresponds to the invoke method from
above's example.

hth,
Sven


Am 10/22/13 1:09 AM, schrieb Caroline Smith:
> Hi everybody! I'm using xtext to implement a language, now I have my
> grammar, but I also want to execute the programs wrote with this, in a
> few words I need an xtext interpreter, but I can't understand if it's
> possible to do it using xtext!
> Can someone help me? :(
> Thank you! :)


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Interpreter for xtext [message #1159147 is a reply to message #1149501] Mon, 28 October 2013 10:23 Go to previous messageGo to next message
Caroline Smith is currently offline Caroline SmithFriend
Messages: 7
Registered: October 2013
Junior Member
I have a java like grammar wrote with xtext, if I remould it in xbase can I use the xabse interpreter to directly evaluate a program wrote with this grammar and have a result without passing to a java code?
Re: Interpreter for xtext [message #1159173 is a reply to message #1159147] Mon, 28 October 2013 10:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Yes

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Interpreter for xtext [message #1159320 is a reply to message #1159173] Mon, 28 October 2013 12:51 Go to previous messageGo to next message
Caroline Smith is currently offline Caroline SmithFriend
Messages: 7
Registered: October 2013
Junior Member
have you some example of this?
Re: Interpreter for xtext [message #1159339 is a reply to message #1159320] Mon, 28 October 2013 13:10 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Hi,

some year ago i did https://github.com/cdietrich/mql

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Resolving type parameters in the Jvm types
Next Topic:Xcore as metamodel for Xtext Grammar
Goto Forum:
  


Current Time: Fri Jul 10 19:23:56 GMT 2020

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

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

Back to the top