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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
978129e
Initial commit
cicr99 Sep 1, 2020
b77ebfc
Creating the nodes of the AST
cicr99 Sep 3, 2020
84d1b36
Creating the attributed grammar for COOL
cicr99 Sep 3, 2020
c2d833a
Adding files to compute an LR1Parser
cicr99 Sep 3, 2020
27213aa
Adding visitor class
cicr99 Sep 3, 2020
56eda5c
Fixing the file names from where the code was importing
cicr99 Sep 6, 2020
35e1441
Adding a tokenizer
cicr99 Sep 6, 2020
071a12a
Adding the methods to create the AST
cicr99 Sep 6, 2020
e8e00cc
Adding Format Visitor
cicr99 Sep 6, 2020
710eb5d
Creating the pipeline
cicr99 Sep 6, 2020
f7cc5f6
Adding files to ignore
cicr99 Sep 7, 2020
1c32fb3
refs #2 - Semantic file added
cicr99 Sep 9, 2020
a2c36f6
refs #2 - Type Collector Visitor
cicr99 Sep 9, 2020
fa9c989
refs #2 - Extending the pipeline
cicr99 Sep 9, 2020
e3348a1
refs #2 - Test Cases added
cicr99 Sep 9, 2020
362d419
refs #3 - Adding self_type to context
cicr99 Sep 10, 2020
4cc1156
refs #3 - Adding Type Builder class
cicr99 Sep 10, 2020
6ede708
refs #3 - Type builder visitor added to the pipeline
cicr99 Sep 10, 2020
580754c
refs #3 - Test cases added
cicr99 Sep 10, 2020
12d4eac
refs #6 - Adding Arithmetic and Comparison nodes to AST
cicr99 Nov 23, 2020
e3d87af
refs #6 - Modifying Type Collector
cicr99 Nov 23, 2020
139cdf7
refs #6 - Modifyng Type Builder
cicr99 Nov 23, 2020
108a01f
refs #6 - Adding Type Checker class
cicr99 Nov 23, 2020
f5cf8c7
refs #6 - Change text in main to test inheritance and order
cicr99 Nov 23, 2020
75c2083
refs #6 - Fix bug in type collector error message
cicr99 Nov 25, 2020
c20561f
refs #6 - Condition for checking conformance to a certain type
cicr99 Nov 25, 2020
c2b5e15
refs #6 - Adding new scopes for conditional branches
cicr99 Nov 25, 2020
f2ab79f
Merge pull request #4 from cicr99/cicr99_t2_Create_Type_Collector
emartglz Nov 26, 2020
4d2a4c2
Merge pull request #5 from cicr99/cicr99_t3_Create_Type_Builder
emartglz Nov 26, 2020
aff7ab3
Merge pull request #7 from cicr99/cicr99_t6_Create_Type_Checker
emartglz Nov 26, 2020
4db34e8
[Checking self] ress#8_Fixing "self" cases in type builder
Nov 26, 2020
249d234
refs #9 - Adding Auto Type class to built-in types
cicr99 Nov 26, 2020
7e66915
refs #8 - changing "self" names in params in function declaration
Nov 27, 2020
1f1367e
refs #11 - Implementing UI
Nov 27, 2020
a3edfd6
Merge pull request #10 from cicr99/kikeXD_t8_Checking_Self
cicr99 Nov 27, 2020
e0bdd28
Adding a comment in ast file
cicr99 Nov 27, 2020
da36b42
refs #9 - Adding Inferencer Manager
cicr99 Nov 27, 2020
d9429e9
refs #9 - Adding Inferencer Manager to Type Builder
cicr99 Nov 27, 2020
987e04e
refs #9 - Adding the Inferencer Manager in Type Checker
cicr99 Nov 27, 2020
b979cb1
refs #9 - Modifying pipeline to add Type Checker and Inferencer Manager
cicr99 Nov 27, 2020
8316811
refs #12 - Checking AUTO_TYPE errors
Nov 28, 2020
3140d8f
refs #12 - removing autotype error from case node
Nov 28, 2020
de56358
refs #9 - Fixing built-in types names
cicr99 Nov 30, 2020
078a423
refs #9 - Adding the index as a parameter to define an attribute in Type
cicr99 Nov 30, 2020
03fb79c
refs #9 - Adding methods to Scope and Type Classes
cicr99 Nov 30, 2020
3412e0c
refs #9 - Self Type class modified
cicr99 Nov 30, 2020
340be81
refs #9 - Fixing bug when finding a variable in the scope
cicr99 Nov 30, 2020
31ab4d9
refs #9 - Changing LCA function to semantic file
cicr99 Nov 30, 2020
9b58455
refs #9 - Changes because of built-in types capital letters
cicr99 Nov 30, 2020
6d289eb
refs #9 - Adding index and fixed types of Self Type
cicr99 Nov 30, 2020
c4ca68a
refs #9 - Methods of Inferencer Manager
cicr99 Nov 30, 2020
80b62a3
refs #9 - Type Inferencer class
cicr99 Nov 30, 2020
74b6b10
refs #9 - Changes in the pipeline to add type inferencer visitor
cicr99 Nov 30, 2020
1d4eb7b
Merge branch 'master' into cicr99_t9_Add_AUTO_TYPE
cicr99 Nov 30, 2020
9b58d4f
refs #9 - Fixing bugs
cicr99 Nov 30, 2020
83d5739
Merge remote-tracking branch 'origin/cicr99_t9_Add_AUTO_TYPE' into ci…
cicr99 Nov 30, 2020
d5e9497
refs #14 - New scope for every variable defined in let node
cicr99 Nov 30, 2020
5a3de40
refs #14 - Fixing methods for adding types to the inferencer manager
cicr99 Nov 30, 2020
328f283
refs #14- Testing the inference using let node
cicr99 Nov 30, 2020
8018b8b
refs # 17 - Adding string and bool constants to the lexer
cicr99 Nov 30, 2020
5cb4b88
refs #17 - Fixing bug in Type Collector
cicr99 Nov 30, 2020
70db4da
refs #17 - Orientation test cases passed
cicr99 Nov 30, 2020
e9938fd
Merge pull request #13 from cicr99/cicr99_t9_Add_AUTO_TYPE
emartglz Nov 30, 2020
a96e90f
Merge pull request #16 from cicr99/cicr99_t14_Fixing_LetNode
emartglz Nov 30, 2020
eddcfe5
Merge pull request #18 from cicr99/cicr99_t17_Bool_and_String_constants
emartglz Nov 30, 2020
5219a4f
Merge branch 'master' of https://github.com/cicr99/TypeInferencer int…
Nov 30, 2020
d00169f
Merge branch 'master' into kikeXD_t12_Checking_autotype
cicr99 Nov 30, 2020
80cdb6d
Merge pull request #19 from cicr99/kikeXD_t12_Checking_autotype
cicr99 Nov 30, 2020
73f6900
refs #11 - Completing pipeline in the UI
Nov 30, 2020
7a7e62e
refs #20 - Readme file
cicr99 Nov 30, 2020
9137ff3
refs #11 - uncomenting main call
Nov 30, 2020
18f426f
refs #11 - Showing only errors and final tree on UI
Nov 30, 2020
45eaa66
Merge pull request #21 from cicr99/cicr99_t20_Read_me_file
emartglz Nov 30, 2020
09ab00b
Merge branch 'master' into kikeXD_t11_Creating_UI
cicr99 Dec 1, 2020
4e9e040
Merge pull request #22 from cicr99/kikeXD_t11_Creating_UI
cicr99 Dec 1, 2020
1670eff
Modifying Read_me file
cicr99 Dec 1, 2020
4ff5eef
Adding a piece of the pipeline that went missing
cicr99 Dec 1, 2020
26c7359
Change in method conforms_to in Type class
cicr99 Dec 1, 2020
3bf6459
Merge pull request #23 from cicr99/Fixing_some_bugs
cicr99 Dec 1, 2020
feb0008
Remove check_conformance from TypeInferencer
cicr99 Dec 1, 2020
b0a9434
Merge pull request #24 from cicr99/Fixing_some_bugs
cicr99 Dec 1, 2020
d19908d
Fixing bug in Case Node in Type Inferencer
cicr99 Dec 1, 2020
5e255f0
Merge pull request #25 from cicr99/Fixing_some_bugs
cicr99 Dec 1, 2020
e729aed
Update README.md
cicr99 Dec 1, 2020
f14682b
refs#1 - Adding lexer code of 1st project
Dec 9, 2020
8d0c62f
refs #1 - Now lexer can take '\' in strings
Dec 9, 2020
9c9809e
refs #1 - Now strings can have '|' inside
Dec 9, 2020
86a1b5c
refs #1 - Now can have in lower and upper names of terminals
Dec 9, 2020
b9056da
Changing title in UI
cicr99 Dec 9, 2020
ffabf68
Organize project structure
cicr99 Dec 10, 2020
f594bb7
Merge branch 'kikeXD_t1_Create_Lexer' into checking_lexer
cicr99 Dec 10, 2020
0eda465
Add \t to spaces and display lexer and parser errors
cicr99 Dec 10, 2020
5d1510e
Fix ReadMe file
cicr99 Dec 12, 2020
3db78ef
Merge branch 'checking_lexer'
cicr99 Dec 12, 2020
3f8288a
Modify error message
cicr99 Dec 12, 2020
944b23f
Conflicts solved for merge
cicr99 Feb 25, 2021
c4aa47c
Merged with base project
cicr99 Feb 25, 2021
22f25c9
Create packages within the project and define work guidelines
cicr99 Aug 15, 2021
2b41c1b
Merge pull request #1 from codersUP/restructure_project
cicr99 Aug 15, 2021
0abee00
Add tokens to lex and split idx into objectid and typeid
cicr99 Sep 5, 2021
d7bfcd2
fix grammar
cicr99 Sep 5, 2021
e583673
Add rules for most of the tokens
cicr99 Sep 7, 2021
aa637b5
Lexer rules finished
cicr99 Sep 12, 2021
83416f2
Added ast of cil and cil code printer(visitor)
Gu4ty Nov 2, 2021
11ec2ee
Added cool2cil visitor
Gu4ty Nov 2, 2021
ec17386
Fixing import in cil_formatter
Gu4ty Nov 2, 2021
476d319
that commit of months ago
Gu4ty Feb 22, 2022
206cf50
fix bugs on lexer
cicr99 Feb 24, 2022
a62682b
build structure for executing project
cicr99 Feb 24, 2022
5d47514
format all files
cicr99 Feb 24, 2022
693efc5
Merge pull request #2 from codersUP/lexer
Gu4ty Feb 24, 2022
48512d0
Modify parser to include token positions
cicr99 Feb 24, 2022
0fcba12
first try cool2cil
Feb 24, 2022
2f3b09d
added tokens to ast nodes
cicr99 Feb 24, 2022
2f2d847
Merge branch 'sintactic_and_semantic_errors' of github.com:codersUP/c…
Feb 24, 2022
57a0485
Modify ast and grammar to receive tokens
cicr99 Feb 25, 2022
1727333
Fix collector visitor to pass tests
cicr99 Feb 25, 2022
9162fe5
Fix builder visitor to pass tests
cicr99 Feb 25, 2022
f756132
add built in functions to cil ast and many other things
Feb 25, 2022
1480543
buildging cil2mips visitor
Gu4ty Feb 25, 2022
8bfcd95
Fix bugs and type checker
cicr99 Feb 25, 2022
3897aca
Merge branch 'sintactic_and_semantic_errors' of github.com:codersUP/c…
Feb 25, 2022
718543c
Add computed type to expression nodes
cicr99 Feb 25, 2022
778f10c
Merge branch 'sintactic_and_semantic_errors' of github.com:codersUP/c…
Feb 25, 2022
dd16568
Modify Inferencer visitor errors
cicr99 Feb 25, 2022
2fb87b3
format files
cicr99 Feb 25, 2022
21e35ea
add cil formatter fixes
Feb 25, 2022
d640ba9
Merge branch 'cool2cil' of https://github.com/codersUP/cool-compiler-…
Gu4ty Feb 25, 2022
534ab61
fix bugs
Feb 25, 2022
c9acd8e
fix imports and clean code
cicr99 Feb 25, 2022
6441d71
add ply to requirements
cicr99 Feb 25, 2022
b37e494
Merge pull request #3 from codersUP/sintactic_and_semantic_errors
cicr99 Feb 25, 2022
29667e8
mips visitor
Gu4ty Feb 26, 2022
9bcefe5
Merge branch 'cool2cil' of https://github.com/codersUP/cool-compiler-…
Gu4ty Feb 26, 2022
8bad127
create package parser and remove unused functions
cicr99 Feb 26, 2022
2b8cccd
create report, code generation missing
cicr99 Feb 26, 2022
1b90d7d
Merge pull request #4 from codersUP/report_and_cleaning
cicr99 Feb 26, 2022
351c666
add cil formatter
Feb 26, 2022
ba886d7
add cool2cil
Feb 26, 2022
1aa8aef
add cil ast
Feb 26, 2022
420491b
fix bug
Feb 26, 2022
6583056
add cool2cil to main
Feb 26, 2022
022bcd9
add cil to report
Feb 26, 2022
e8535e8
comment cil tree print
Feb 26, 2022
f69f0f6
Merge pull request #5 from codersUP/kikeXD_cool2cil_to_master
emartglz Feb 26, 2022
0964fbe
fixing bugs
Gu4ty Feb 26, 2022
23d0019
fix bug
Feb 26, 2022
d1307ba
fix bugs
Feb 26, 2022
fe182fe
allocate with malloc
Gu4ty Feb 26, 2022
8f7ad42
testing shit
Gu4ty Feb 26, 2022
8477674
fix pass getAttr
Gu4ty Feb 26, 2022
c054434
Merge branch 'mips_ast' into testing
Gu4ty Feb 26, 2022
3703fc1
fix bugs
Feb 27, 2022
f39ab20
fxix bug
Feb 27, 2022
fab8b7b
Merge pull request #6 from codersUP/kikeXD_fix_bug_cool2cil
emartglz Feb 27, 2022
67747bc
mips temp folder
Gu4ty Feb 27, 2022
492bdc8
Merge branch 'master' of github.com:codersUP/cool-compiler-2021 into …
Feb 27, 2022
29bc002
add cil to mips visitor
Feb 27, 2022
9e4827c
fix bug in type inferencer about nested scopes
cicr99 Feb 27, 2022
3113b57
organize project in packages
cicr99 Feb 27, 2022
32d7ce4
update report
cicr99 Feb 27, 2022
55a58fe
Merge pull request #7 from codersUP/testing
cicr99 Feb 27, 2022
6584999
fix issue in alloc instruction
Feb 27, 2022
bc4818f
fixing hello world
Gu4ty Mar 1, 2022
1891c23
tests in codegen not working
Gu4ty Mar 1, 2022
692cf52
codegen tests fixed
Gu4ty Mar 1, 2022
a0504b2
Deleting commented code
Gu4ty Mar 1, 2022
b5ba5ab
mips section in report
Gu4ty Mar 1, 2022
e77a91a
Merge branch 'master' into merging_mips
cicr99 Mar 2, 2022
0a40a17
refactoring code
cicr99 Mar 2, 2022
1f73db1
remove some unused code on cil section
cicr99 Mar 2, 2022
2384b04
update report
cicr99 Mar 2, 2022
f37b3bf
Merge pull request #8 from codersUP/merging_mips
cicr99 Mar 2, 2022
df4862e
remove unused code in cool script
cicr99 Mar 3, 2022
db9dbb6
Merge pull request #9 from codersUP/fix_bugs_on_code
cicr99 Mar 3, 2022
30d4570
changing default goal in makefile
cicr99 Mar 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,4 @@ dmypy.json

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

.vscode/
239 changes: 239 additions & 0 deletions doc/report.md

Large diffs are not rendered by default.

Binary file added doc/report.pdf
Binary file not shown.
18 changes: 9 additions & 9 deletions doc/team.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
members:
- name: Nombre Apellido1 Apellido2
github: github_id
group: CXXX
- name: Nombre Apellido1 Apellido2
github: github_id
group: CXXX
- name: Nombre Apellido1 Apellido2
github: github_id
group: CXXX
- name: Carmen Irene Cabrera Rodríguez
github: cicr99
group: C412
- name: David Guaty Domínguez
github: Gu4ty
group: C412
- name: Enrique Martínez González
github: kikeXD
group: C412
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest
pytest-ordering
ply
34 changes: 34 additions & 0 deletions src/code.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Main inherits IO {
number: Int <- 6;

main () : Object {
testing_fibonacci(number)
};

testing_fibonacci(n: Int) : IO {{
out_string("Iterative Fibonacci : ");
out_int(iterative_fibonacci(n));
out_string("\\n");

out_string("Recursive Fibonacci : ");
out_int(recursive_fibonacci(n));
out_string("\\n");
}};

recursive_fibonacci (n: AUTO_TYPE) : AUTO_TYPE {
if n <= 2 then 1 else recursive_fibonacci(n - 1) + recursive_fibonacci(n - 2) fi
};

iterative_fibonacci(n: AUTO_TYPE) : AUTO_TYPE {
let i: Int <- 2, n1: Int <- 1, n2: Int <- 1, temp: Int in {
while i < n loop
let temp: Int <- n2 in {
n2 <- n2 + n1;
n1 <- temp;
i <- i + 1;
}
pool;
n2;
}
};
};
Empty file added src/compiler/__init__.py
Empty file.
Empty file added src/compiler/cmp/__init__.py
Empty file.
252 changes: 252 additions & 0 deletions src/compiler/cmp/ast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
from .semantic import Type
from .utils import Token, emptyToken
from typing import List, Optional, Tuple, Union


class Node:
def __init__(self, token: Token):
self.token = token


class DeclarationNode(Node):
pass


class ExpressionNode(Node):
def __init__(self, token: Token, computed_type: Optional[Type] = None):
super().__init__(token)
self.computed_type = computed_type


class FuncDeclarationNode(DeclarationNode):
def __init__(
self,
token: Token,
params: List[Tuple[Token, Token]],
return_type: Token,
body: ExpressionNode,
):
self.id = token.lex
# `param` is (nameToken, typeToken)
self.params = params
self.type = return_type.lex
self.typeToken = return_type
self.body = body
self.token = token


class AttrDeclarationNode(DeclarationNode):
def __init__(
self,
idx: Token,
typex: Token,
expr: Optional[ExpressionNode] = None,
token: Token = emptyToken,
):
self.id = idx.lex
self.idToken = idx
self.type = typex.lex
self.typeToken = typex
self.expr = expr
self.token = token


class ClassDeclarationNode(DeclarationNode):
def __init__(
self,
idx: Token,
features: List[Union[FuncDeclarationNode, AttrDeclarationNode]],
token: Token,
parent: Optional[Token] = None,
):
self.id = idx.lex
self.tokenId = idx
self.token = token
self.parent = parent
self.features = features


class ProgramNode(Node):
def __init__(self, declarations: List[ClassDeclarationNode]):
super().__init__(emptyToken)
self.declarations = declarations


class AssignNode(ExpressionNode):
def __init__(self, idx: Token, expr: ExpressionNode, token: Token):
super().__init__(token)
self.id = idx.lex
self.idToken = idx
self.expr = expr


class CallNode(ExpressionNode):
def __init__(
self,
obj: ExpressionNode,
idx: Token,
args: List[ExpressionNode],
cast_type: Token = emptyToken,
):
super().__init__(idx)
self.obj = obj
self.id = idx.lex
self.args = args
self.type = cast_type.lex
self.typeToken = cast_type


class CaseBranchNode(Node):
def __init__(self, token: Token, idx: Token, typex: Token, expr: ExpressionNode):
self.token = token
self.id = idx.lex
self.idToken = idx
self.typex = typex.lex
self.typexToken = typex
self.expression = expr


class CaseNode(ExpressionNode):
def __init__(
self, expr: ExpressionNode, branch_list: List[CaseBranchNode], token: Token
):
super().__init__(token)
self.expr = expr
self.branch_list = branch_list


class BlockNode(ExpressionNode):
def __init__(self, expr_list: List[ExpressionNode], token: Token):
super().__init__(token)
self.expr_list = expr_list


class LoopNode(ExpressionNode):
def __init__(self, cond: ExpressionNode, body: ExpressionNode, token: Token):
super().__init__(token)
self.condition = cond
self.body = body


class ConditionalNode(ExpressionNode):
def __init__(
self,
cond: ExpressionNode,
then_body: ExpressionNode,
else_body: ExpressionNode,
token: Token,
):
super().__init__(token)
self.condition = cond
self.then_body = then_body
self.else_body = else_body


class LetVarNode(Node):
def __init__(
self,
idx: Token,
typex: Token,
expr: Optional[ExpressionNode] = None,
token: Token = emptyToken,
):
self.token = token
self.id = idx.lex
self.idToken = idx
self.typex = typex.lex
self.typexToken = typex
self.expression = expr


class LetNode(ExpressionNode):
def __init__(self, id_list: List[LetVarNode], body: ExpressionNode, token: Token):
super().__init__(token)
self.id_list = id_list
self.body = body


class AtomicNode(ExpressionNode):
def __init__(self, token: Token):
super().__init__(token)
self.lex = token.lex


class UnaryNode(ExpressionNode):
def __init__(self, expr: ExpressionNode, symbol: Token):
super().__init__(symbol)
self.expr = expr


class BinaryNode(ExpressionNode):
def __init__(self, left: ExpressionNode, right: ExpressionNode, symbol: Token):
super().__init__(symbol)
self.left = left
self.right = right


class ArithmeticNode(BinaryNode):
pass


class ComparisonNode(BinaryNode):
pass


class ConstantNumNode(AtomicNode):
pass


class ConstantStringNode(AtomicNode):
pass


class ConstantBoolNode(AtomicNode):
pass


class VariableNode(AtomicNode):
pass


class InstantiateNode(AtomicNode):
pass


class PlusNode(ArithmeticNode):
pass


class MinusNode(ArithmeticNode):
pass


class StarNode(ArithmeticNode):
pass


class DivNode(ArithmeticNode):
pass


class LeqNode(ComparisonNode):
pass


class LessNode(ComparisonNode):
pass


class EqualNode(BinaryNode):
pass


class VoidNode(UnaryNode):
pass


class NotNode(UnaryNode):
pass


class NegNode(UnaryNode):
pass
Loading