Software Construction
Gregor v. Bochmann
Winter 2009
, 2010, 2012, 2013

Lab-8

Originally prepared by  Abdelilah Maach and Alan Williams; revised 2009 by G.v.B.

A Simple Compiler in Java

We saw the "Very Simple Programming Language" (VSPL) in Lab 7. During this lab, we learn how to write a compiler for this language in Java using the recursive descent methodology.

Part A: Study a given compiler for VSPL

The development of a compiler for VSPL in Java is explained here.

  1. Please study the explanations given and the Java code
    • for the lexical analyser
    • for the syntactic analyser and
    • for the evaluation (execution) of the expressions as performed by the code included in the syntax analyser.
  2. Execute the compiler with some example programs. Note: You can find some example here.
  3. When you understand the Java program, go to Part B.

Part B: Extend the given compiler in order to support the language extensions that were designed during Lab 7.

Please consider the grammar extensions that were introduced during Lab 7. Extend the compiler to support these extensions by doing the following steps:

  1. Write down the recursive automata for the extended syntactic rules, in a manner similar to what is explained for VSPL.
  2. Write the recursive Java procedures for the new non-terminals of the grammar, and modify the Java procedures for the non-terminals of the non-extended VSPL, as appropriate. - It is suggested to concentrate first on the syntactic aspects and leave the issues of expression evaluation for later (if time permits).
  3. Revise the lexical analyser in order to include the new terminal tokens that are required for the extensions.
  4. Debug your extended compiler by executing it with some example programs. You should use an example such as a+b*c to ensure that the order of operations is performed correctly.