CMPU-331 Compilers (Fall 2018)

Overview

Over the semester you have crafted a large and complex program, one which translates instructions from one language to another. Congratulations on all you have achieved so far!

The purpose of this phase is two-fold. Firstly, the opportunity to resubmit components which you have worked on since they were graded, with any improvements to the code and bug fixes you have made. Secondly, as this is in part a software design course, you must ensure that your code is well-formed and conforms to good object-oriented design.

Requirements

  1. Your code should be as complete and bug-free as possible. Your compiler must be able to translate any valid Vascal program so it can be run in TVI.
  2. Your code must adhere to the coding standards and conventions provided.

Coding Standards and Conventions

Java

Design
  • Your project must adhere to a good object-oriented model. Classes must be designed to be functional program units, with correct responsibilities and control. Connections between classes should be clear and logical.
  • Member variables and functions must be declared private, except for only those functions which must be called from outside that function.
  • Only functions which must be declared static may be declared static. (e.g. the main() function in Java.)
  • You must define a Compiler class, which wraps up the rest of the compiler classes and has responsibility for managing operations (i.e. initialisation, construction, calling, clean-up). This should be created in main().
  • You must define a Main class, which creates and initialises a Compiler object before passing control to that object. (i.e. the Compiler object is not Main).
Conventions
  • All class member functions and member identifier names (except for those dictated by Java; e.g. main()) must be in UpperCamelCase. For example, GetNextToken(), SemanticStack.
  • All local identifiers (including formal parameter names) must be in lower case only.
  • Curly braces go on a line by themselves. They are indented at the level of the current scope (not the enclosed scope).
  • Conditional or iteration statements whose statements are only one line long do not require curly braces; e.g.:
for (x = 0; x < 20; ++x)
      (for (y = 0; y < 20; ++y)
          if (((x + y) * (x * y)) % 2 == 0)
          {
              System.out.println(x)
              System.out.println(y)
          }
  • Code must be tidily indented with 4 spaces (usually 1 tab) per scoping level.
  • Reserved words which require parentheses (e.g. if (…)) must have a space between the reserved word and the parenthesis. Other functions (e.g. GetNextToken()) must not have this space.
  • Operators, identifiers and constants should be broken up by spaces, similarly to the example above. Delimiters (semicolons and commas) should be followed by one space.
Comments
  • Each class should have a header comment describing the class and its function. This should use the style of comment.
  • Each function should have a comment above it describing what the function does. This should use the style of comment.
  • Comments should be descriptive but not unnecessarily verbose.
  • Comments within the body of a function should be separated from the code around them by line breaks; e.g.:
    Here is some code
    Here is some more code
    
    // The next bit of code is more complex so I'm describing its operation
    
    Gosh, what complicated and difficult code!
    I'm glad I wrote myself a comment!

Python

Design
  • Your project must adhere to a good object-oriented model. Classes must be designed to be functional program units, with correct responsibilities and control. Connections between classes should be clear and logical.
  • Python does not enforce access control. Member variables and functions which would otherwise be declared private, should begin with a single underscore character; e.g. _SemanticStack, _Create(…). 'Private' functions may not be called from outside the class.
  • You must define a Compiler class, which wraps up the rest of the compiler classes and has responsibility for managing operations (i.e. initialisation, construction, calling, clean-up).
  • You should have a separate main file (e.g. main.py, mainprog.py) which creates and initialises a Compiler object before passing control to it.
Conventions
  • All class member functions and member identifier names (except for those dictated by Python; e.g. dict.keys()) must be in UpperCamelCase. For example, GetNextToken(), SemanticStack.
  • All local identifiers (including formal parameter names) must be in lower case only.
  • Reserved words which require parentheses (e.g. if (…)) must have a space between the reserved word and the parenthesis. Other functions (e.g. GetNextToken()) must not have this space.
  • Operators, identifiers and constants should be broken up by spaces, similarly to the example above. Delimiters (semicolons and commas) should be followed by one space.
Comments
  • Each class should have a comment describing the class and its function.
  • Each function should have a comment above it describing what the function does.
  • Comments should be descriptive but not unnecessarily verbose.
  • Comments within the body of a function should be separated from the code around them by line breaks; e.g.:
    Here is some code
    Here is some more code
    
    # The next bit of code is more complex so I'm describing its operation
    
    Gosh, what complicated and difficult code!
    I'm glad I wrote myself a comment!

Submission