|
|
Re: Interpreter for xtext [message #1149501 is a reply to message #1149067] |
Tue, 22 October 2013 06:03 |
Sven Efftinge 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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03183 seconds