Child pages
  • Code Generation with Xtend
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This tutorial is not finished. Don't start working on it yet!

Welcome to the second tutorial about Xtend. This time, you will take imperative language models and generate code for them in your favourite programming language. While we personally recommend Java, there's nothing stopping you from generating C code, PHP code, or anything else the constructs of our simple language model can be transformed into. We would just like to ask you to refrain from generating code in any esoteric programming language... (wink)

The code generation you will implement here should not be optimized for generating the kinds of programs your transformation generates. Instead, we expect it to work for any valid program model. Further down, you will find an archive with example programs you can test your code generation on.

Contents

Preliminaries

You should have everything you need for this tutorial:

  • The Turing Machine metamodel you created in the third tutorial.
  • The Imperative Programming Language metamodel you downloaded in the previous tutorial.
  • The Turing-Machine-to-Imperative-Programming-Language transformation you developed in the previous tutorial.

Generating Code with Xtext

We will of course need a new Xtend class that will take care of the code generation.

  1. Add a new Xtend Class to the compiler project, preferrably in a new package called de.cau.cs.rtprak.login.compiler.codegen.

Making the Code Generation Available

As in the previous tutorial, add a menu contribution to the ...compiler.ui plug-in to make the code generation available in the interface. Since your code generation implementation is expected to work for arbitrary (valid) instances of the programming language model, your menu contribution should be available for all programming language models and their textual representations. (".imperative" and ".pseudo" files)

Testing Your Implementation

ToDo

Provide sample programs for testing.

To test your implementation, you can use these sample programs. Since we haven't included comments in the textual syntax (or the model, for that matter), we'll just have to hope that the programs are self-explanatory...

  • No labels