Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodersUP - Cool Compiler #46

Open
wants to merge 176 commits into
base: master
Choose a base branch
from
Open

CodersUP - Cool Compiler #46

wants to merge 176 commits into from

Conversation

cicr99
Copy link

@cicr99 cicr99 commented Feb 25, 2022

No description provided.

cicr99 and others added 30 commits September 1, 2020 12:15
- pycompiler.py contains all the classes that are necessary to create a grammar
- grammar.py contains the declaration of the language: terminals, non terminals, main symbol and the productions, each of them with its attribute.
This is a provisional tokenizer. The COOL code must be written separated by spaces, so that it can create the list of tokens.
This tokenizer can be replaced for a lexer later.
This visitor allows to print each node of the ast, which includes information about it
the main.py file contains the initial method run_pipeline. Right now, this method takes the text (COOL code) and takes it to the point of constructing the ast.
It also contains a case to test the program
This file contains the classes to manage the types, attributes and methods declared in the code. It also contains the class Context which handles all the mentioned classes. In addition, ObjectType, IOType, IntType, StringType and BoolType were created to represent the built-in types of COOL
-This visitor runs through the AST collecting the types defined by the programmer.
- After collecting all the types defined and adding to the context the built-in types of COOL, the method check_parents() is in charge of setting each type parent: if the parent is None, it sets Object as the parent of this type; if the parent declared is not defined then it saves the error and sets Object as the parent of this type.
- Lastly check_cyclic_inheritance looks for cycles in the inheritance hierarchy; in case of finding any, it saves the error and sets object as the parent of the type who closes the cycle. The result of this method depends on the way the types were defined in the code
Now that the type collector was added, the pipeline was modified so that after printing the ast it shows the results of running the type collector visitor
This file was added in order to change the text of the main file easily, and to have cases to test each stage of the code
If self_type is not added to context, it is considered as an error when the returned type of a method is SELF_TYPE, since this type is not defined in the context.
If there is a better way to handle self_type it will be fixed later.
The type builder runs through the ast an sets for every type that was defined its attributes and methods.
When this process is finished it also checks that the program contains a Main class, and that this class contains a method main
After collecting all the types, run_pipeline method calls type builder visitor and prints the resulting stage of the context and errors
More test cases were added to check the new features
Both classes inherit from Binary Node
- Arithmetic Node refers to the operations: plus, minus, star and div. These are supposed to receive two integers and they return an integer as well.
- Comparison Node refers to LeqNode and LessNode. They both receive two integers and return a bool value.
- The behavior of Equal Node can variate depending on the type of the elements it receives, so it inherits from Binary Node instead.
- When checking a Class Declaration Node, if it doesn't have a valid id, its id will be modified until the type of the class can be added to the context, so the information of that class doesn't get lost
- Order Types method added: After setting parents of every class the graph that represents the hierarchy of types is a tree; hence this method will change the order of the list of class declarations in the program node according to their depth in the mentioned tree
- Code added in the method of Attribute Declaration Node, so if the id of the attribute wasn't valid for some reason, it will change the id until it can be defined in the current type
It hasn't been tested yet
When visiting then and else branches in a Conditional Node, a child scope should be created in both cases
@jpconsuegra jpconsuegra self-requested a review March 8, 2022 13:23
@jpconsuegra jpconsuegra self-assigned this Mar 8, 2022
@jpconsuegra
Copy link
Collaborator

jpconsuegra commented Mar 8, 2022

Evaluación

  • Carmen Irene Cabrera Rodríguez
  • David Guaty Domínguez
  • Enrique Martínez González

Requisitos mínimos (3)

  • El proyecto pasa todos los tests
  • El informe existe y explica el uso del compilador y la arquitectura básica

Requisitos intermedios (4)

  • Se implementaron las fases de chequeo semántico de forma separada y utilizando patrones adecuados
  • La arquitectura del compilador está organizada de forma coherente y mantenible

Requisitos extra (5)

  • Se implementaron las fases de generación de código intermedio y código objeto con patrones adecuados
  • Se resolvieron los problemas de representación de objetos en memoria e invocación de métodos virtuales de forma eficiente
  • Se resolvieron los problemas de boxing/unboxing de forma eficiente

Extras

  • Implementaron SELF_TYPE
  • Implementaron AUTO_TYPE

Comentarios

  • No encontré en el informe cómo resuelven los problemas de boxing/unboxing.

Nota final

Evaluación Nota
Final 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants