**GROUP: 65**
| Name | Number | Self Accessment | Contribution |
|--|--|--|--|--|--|--|--|
| Henrique Ferreira | 201605003 | 14 | 40% |
| Leonor Freitas | 201207603 | 13 | 35% |
| Mário Sousa | 201806363 | 12 | 25% |
| Rodrigo Abrantes | - | - | -% |
**GLOBAL Grade of the project: 13**
## **SUMMARY:**
The intention of this assignment was to develop a compiler, named jmm, which is able to translate Java-- programs into java bytecodes (Jasmin) and executes the program. The compiler follows a strict but practical compilation flow.
Some of the stages included are:
1. Creation of the grammar with the specified lexical rules;
2. Error treatment and recover mechanisms for while mechanisms;
3. Generation of an Abstract Syntax Tree (AST);
4. Generation of a JSON tree from the AST;
5. Creation of a Symbol Table;
6. Semantic analysis;
7. Generation of Ollir code;
8. Generation of Jasmin file from the information in the Ollir code;
Note: All error reports are created and displayed through the provided Report's library.
## **DEALING WITH SYNTACTIC ERRORS:**
The syntatic analysis was made to detect errors on the while expression up to a limit of 10 errors as specified by the project´s requirements. Once it reaches that limit the proccess is aborted.
## **SEMANTIC ANALYSIS:**
We implemented all of the rules that were specified in the project.
As the project progressed, there were additional verifications to ignore the newest appearance of errors that were not supposed go through the analysis stage, though we could not take all of them into account. For example, for this stage of the project, the methods were called with a "THIS" token followed by a "DOT" token and an "IDENTIFIER" token. But in the latest stages there were sittuations where the "THIS" token was instead an "IDENTIFIER" token.
Additionaly, when searhing fot the existence of a method, the search is made using the method's signature, which means, a method with the same name and same number of parameters as another, can still be distinguished through its parameters.
## **CODE GENERATION:**
The Ollir and Jasmin code generations were made independently therefore, some instructions in the Jasmin language may have not been implemented in the Ollir language, resulting in dead code. On the other side, some of the instructions in Ollir might have not been implemented in the Jasmin language, resulting in errors on specific programs.
In Ollir, there has been code generated for class and method declarations, arithmetic expressions, method calls, new expressions and assignments. There has been no code generated for ifs, loops or array manipulations. There may also be some incomplete code in the other instructions for which ollir code is being generated, such as operations with booleans.
The most important instructions were implemented in Jasmin: integer manipulations, array manipulations (with some more intructions like the length and the element accessor), conditions, if/else, loops, get/put fields, equations and several invoke instructions. Amongst this instructions there are also some instructions related to booleans, strings, objects and other not so important or not so complete instructions. Some instructions may have been missed out or just forgotten.
## **TASK DISTRIBUTION:**
Name | Checkpoint 1 | Checkpoint 2 | Checkpoint 3 |
|--|--|--|--|
Henrique Ferreira | 60% | 50% | 33% |
Leonor Freitas | 40% | 25% | 33% |
Mário Sousa | 0% | 25% | 33% |
Rodrigo Abrantes | -% | -% | -% |
### **PROS:**
- The tool developed has a great amount of easily understandeable feedback through console logs to show the overall process of the tool.
- The operators precedence is well implemented meaning, for example, a multiplication is always on a higher node than an addition.
- No stage has any apparent errors.
- The tool has no additional libraries beyong the ones provided.
### **CONS:**
- As said in the semantic analysis above, some errors may appear due to some verifications not being made, however these errors are Reports and not actual java errors.
- Both Jasmin and Ollir were incompleted due to the enormous amount of code generation possible for both ends and the lack of documentation provided in many cases.
- Due to the above problem, no complicated tests were made to prove the tool's potential.