---
# System prepended metadata

title: COMP

---

# COMP

## Self-Evaluation

**GROUP:** 7E

 
* Carolina Rosemback, up201800171, 17, 25%
* Diogo Filipe Martins, up201806280, 17, 25%
* Emanuel Trigo, up201605389, 17, 25%
* Iohan Sardinha, up201801011, 17, 25%

 
**Global Grade of the project:** 17

 
## Summary:
In this project, we built a compiler for programs written in Java-- language, applying the theoretical principles learnt in the COMP classes. We would say that this projetc has three major parts: **Dealing with Syntatic Errors**, **Semantic Analysis** and **Code Generation**.


## Dealing with Syntatic Errors:
There are error treatments and recovery mechanisms for while conditions just like it was requested. When an error is found in the conditional statement of a while, the compiler ignores every token until the ';' token of the end of the file, showing an error message indicating which tokens were expected and the line and column where the error occurred.
For each error found during the syntatic analysis it's appended to a list with a fixed 20 error maximum. If the limit is reached only the first twenty errors are shown, all errors are shown in order in the end of this step.
 


## Semantic Analysis:

Regarding the Semantic Analysis, our compiler does the following:

* **Imports**
-- Checks if the default constructor was imported for the super class;
-- Checks if the super class was imported;
-- Warns when an import is repeated.
-- Alow any method from an import to be called, and infer's it's type according to the assigned variable type

* **Variables**
-- Allows for constructor other than the default;
-- Checks if the constructor has appropriate parameters;
-- Checks the redefinition of global variables;
-- Checks the redefinition of local variables.

* Type Verification in Operations
-- Checks if operations are between elements of the same type;
-- Checks if boolean operations are with booleans only;
-- Conditional Expression only excepts operations, variables or function calls that return boolean;
-- Doesn't allow operations between arrays;

* Type Verification in Arrays
-- Allows only the array access to arrays;
-- Allows only int values to index accessing array;
-- Allows only int values to initialize an array;

* Type Verification in Assignments
-- Checks if the assignment is between the same type;

* Initialization
-- Raises an error if variable has not been initialized,
-- Assumes the parameters as initialized;

* Methods
-- Allows the method to be declared after or before any other function calls it
-- Allows the overload of methods;
-- Allows only the calls to methods that exist with the correct signature;
-- Checks if the method was imported or belongs to the class in question;
-- Checks if the method call is for the current class or if it is a method of the super class;
-- Verifies if the parameter types match the method signature;
-- Verifies if the return type of method matches the assign variable;
 

## Code Generation:
The code generation step takes the tree generated by the synstatic analysis step and first creates a Ollir code then uses it to create a jasmin code.
Both Ollir and jasmin generate codes for:
-- Classes
-- Class fields
-- Methods
-- Method calls
-- Variables, assigns and expressions
-- Ifs and elses
-- Whiles
-- Arrays creation, assign and length
-- Object creation
-- Manage register number and default instructions if the number is less then 4, in jasmin
 


## Task Distribution: 
* Carolina Rosemback: Parser, Syntatic Errors, Ollir;
* Diogo Filipe Martins: Parser, Syntatic Errors, Ollir;
* Emanuel Trigo: Ollir, Jasmin;
* Iohan Sardinha: Parser, Syntatic Errors, Semantic Analysis, Jasmin.

 

**PROS:** 
-- Very organized code for main, JJTree, Semantic Analisys and jasmin code generation 
-- Runs a complete semantic analisys
-- Generates correcectely ollir and jasmin code
-- Generates runnable jasmin code 

 


**CONS:** 
-- A little unorganized code in TableBuilderVisitor and OllirVisiton
-- Lack of optimizations
-- Could have more enhancements to the basic Java-- sintax which is very limited