Search code examples
javaeclipseprogramming-languagesxtext

Can parse but not evaluate xtext arithmetics example


I'm having a look at XText within the Eclipse framework, and have a question about the arithmetics example. I seem to be able to parse expressions but not evaluate them and wonder if this should be so. This is my workflow:

  1. Create a new Example projext. Choose XText Simple Arithmetics Example.

  2. Open Arithmetics.xtext and choose Run -> External Tools -> Run as -> "Generate XText artifacts". No Error messages so far as. A bunch of info messages on the form:

    119 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering project org.eclipse.xtext.example.arithmetics at 'file:/H:/2017/xtextworkspace/org.eclipse.xtext.example.arithmetics/'

    119 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering project org.eclipse.xtext.example.arithmetics.tests at 'file:/H:/2017/xtextworkspace/org.eclipse.xtext.example.arithmetics.tests/'

  3. Open plugin.xml and click "Launch an Eclipse application". A second window now opens up and I can now create a new project and start typing expressions.

  4. Create a new project and a new file calles a.calc with this content:

(I also seem to have to create a new Java project here which seems a bit counter-intuitive. Shouldn't it be possible in your new IDE to have a menu option here like "Create new Calc Project"?).

module A
def a:2;
def b:1;
a+b;

The editor seem to parse fine, content assist is working and it tells me if I do something wrong. But isn't it possible to actually run the program? I would like to have an option here similar to "Run -> Run as -> Calc application" Is this not included in the Arithmetics example? I feel like it should be because what else would be the purpose of the calculator.java class? How do I make it print out the value?


Solution

  • you get the expressions evaluated by typing "enter" inside the editor

    module A
    def a:2;
    def b:1;
    a+b;
    // = 3
    1+1;
    // = 2
    33*11;
    // = 363