Category Archives: WS0910

Compiler Construction, WS0910

This homework continues the Xtext exercise from homework #10. This time, you have to generate Java code from EngineeringC code. Add this example model to your EngineeringC project:


EngineeringCDiagram diag {
  ECBlockDecl test {
    ECStore x {
      value : "0"
    }

    ECStore y {
      value : "7"
    }

    ECComputeBlock comp1 {
      expression : "x = 6 * y"
    }
  }

  ECBlockDecl callTest {
    ECStore z {
      value : "0"
    }

    ECBlockAppl callTest {
      instanceof : test
    }

    ECComputeBlock comp2 {
      expression : "z = x + 42"
    }
  }
}

(Remember to first modify your grammar before creating a code generation template!)

The generated Java code should calculate the correct result for all ECComputeBlocks. To ensure this, create a JUnit test in the same package as the generated class. Call the generated methods from the test and ensure that the expected values are computed. To make cross-block variable access possible, you have to modify the Xpand template so that these variables are accessible from the generated methods.

Xtext Workflow from the lecture:

<workflow>
  <property file="workflow.properties"/>
  <component	class="org.eclipse.xtext.MweReader" uri="${modelFile}">
    <register class="de.unikassel.se.compilerbau.ECStandaloneSetup"/>
  </component>

  <component id="generator" class="org.eclipse.xpand2.Generator">
    <metaModel id="mm" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
      <metaModelPackage value="de.unikassel.se.compilerbau.eC.ECPackage"/>
    </metaModel>
    <expand value="GenerateEC::Root FOR model"/>
    <outlet path="${srcGenPath}/">
      <postprocessor class="org.eclipse.xpand2.output.JavaBeautifier"/>
    </outlet>
  </component>
</workflow>

Helpful links:

Compiler Construction, WS0910

Please follow the instructions given in the lecture to complete the assignment.

* Download/install Xtext, preferably using a complete Eclipse distribution from http://xtext.itemis.com/xtext/language=en/23947/downloads
* Create a new workspace and a new Xtext project
* Write a grammar corresponding to the simplified EngineeringC model shown in the lecture
* Run the generated workflow and test the parser with some EngineeringC diagrams

To hand in your homework, ZIP the Eclipse workspace which contains the Xtext project and upload the ZIP file to your CVS repository. Deadline is Friday, Feb. 5th.

Compiler Construction, WS0910

Implement code generation for functions and function calls. You should test and implement the following features:

  • Generate a function from a funcDecl, using a separate InstructionList and adrTab.
  • Generate function calls, pushing actual parameters onto the stack and invoke a previously generated function by name.

You do not need to implement parameter overloading or access to global variables from functions.

Deadline is before the next lecture, which will be held Jan. 22nd. Until then, happy holidays everyone!