-
Notifications
You must be signed in to change notification settings - Fork 43
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
cicr99
wants to merge
176
commits into
matcom:master
Choose a base branch
from
codersUP:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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
Fixes #2 - Type Collector Visitor
Fixes #3 - Type Builder visitor
Fixes #6 - Type Checker class
Kike xd fix bug cool2cil
Organize project in packages
store word after creating an instance
Merging mips
remove unused code in cool script
Evaluación
Requisitos mínimos (3)
Requisitos intermedios (4)
Requisitos extra (5)
Extras
Comentarios
Nota final
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.