Child pages
  • Code Generation with Xtend

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Add a new Xtend Class to the compiler project, preferrably in a new package called de.cau.cs.rtprak.login.compiler.codegen.
  2. Add a method to your class that starts the code generation. It can look something like this:

    Code Block
        /**
         * Generates Java code for the given imperative program.
         * 
         * @param program the imperative program to generate code for.
         * @return code that implements the imperative program.
         */
        def String generateCode(Program program) '''
            YOUR CODE GENERATION
        '''
  3. Decide, which programming language to generate code for. The easiest will probably be Java, but other languages should be fine too. Your code is supposed to generate code that is complete and compilable in your target language. Make sure that your code generation supports transformed Turing Machines as well as the sample programs we provide below.

Here's a few hints as to what your implementation should support:

  • The imperative language supports arrays, which you could implement as lists or arrays. Either way, you should make sure that the generated code does not throw exceptions for reasonable array indices. Ideally, your code makes no assumptions on array sizes.
  • You will have to generate some kind of a main method which takes care of initializing input variables, running the program, and printing the result. To initialize input variables, your generated code could ask the user for input on the console.
  • Try to ensure that the generated code is readable and properly indented.

Making the Code Generation Available

...