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

ready #51

Open
wants to merge 90 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
a2285e2
cmp files
Dec 14, 2021
c212a41
Lexer
Dec 14, 2021
f5ce791
cool grammar
Dec 14, 2021
f204843
ast
Dec 14, 2021
84c7c4c
parser
Dec 14, 2021
59abcc7
type_collector-type_builder
Dec 14, 2021
06712f4
fixing some issues for type_check
Dec 15, 2021
c9f53ac
ast with tokens files-columns
Dec 15, 2021
08ec176
cool grammar lines-columns
Dec 15, 2021
74b84d1
type checker
Dec 15, 2021
80b120b
semantic fixed
Dec 15, 2021
0ae8c6d
type builder fixed
Dec 15, 2021
f6607a7
fixing tokens in ast
Dec 15, 2021
cb800e7
working on type errors
Dec 15, 2021
d2f0420
main
Dec 16, 2021
9373a10
changing lin-col in some tokens like tests
Dec 16, 2021
f04e915
execute project
Dec 16, 2021
5fa3965
changing some semantic errors like tests
Dec 16, 2021
d72b55d
including fixed_tokens
Dec 19, 2021
12dbd4f
fixed tokens in ast
Dec 19, 2021
7a13614
update errors tags and fixind variables in parents
Feb 13, 2022
deac2a5
Update requirements.txt
Alexx-4 Feb 15, 2022
ce0fabc
updating all
Feb 15, 2022
0de3bf1
deleting unnecesary stuff
Feb 15, 2022
44538fb
update main
Feb 15, 2022
2ff9e92
instructions to run code
Feb 15, 2022
30572b8
updating code
Feb 15, 2022
63922dd
Update requirements.txt
Alexx-4 Feb 15, 2022
3c6dc70
update lexer
Feb 15, 2022
71ebe1d
modifing lexer
Feb 15, 2022
f5c351e
fixing grammar-parser
Feb 16, 2022
32ca3c0
updating
Feb 16, 2022
230b01c
lexer-parser ready
Feb 16, 2022
b60c5e1
parser ok
Feb 16, 2022
9768b4f
writing errors like test
Feb 16, 2022
e677043
updating semantic
Feb 16, 2022
4c2642e
acopling errors
Feb 16, 2022
87c4a66
update semantic errors
Feb 16, 2022
f3e5818
updating code
Feb 16, 2022
99b575a
darian is anormal
Feb 16, 2022
22079ac
changing semantic errors format
Feb 16, 2022
5ee11cf
errors like test
Feb 16, 2022
f65bdfc
semantic ok
Feb 16, 2022
0aad480
Update requirements.txt
Alexx-4 Feb 18, 2022
cf1f2f7
Update requirements.txt
Alexx-4 Feb 18, 2022
eab9984
Creating Cool_to_Cil visitor template
Darian10 Feb 18, 2022
1175eee
creating cil ast
Feb 19, 2022
0390fd8
Merge branch 'master' of https://github.com/BeginnerCompilers/cool-co…
Feb 19, 2022
f5c1237
modifying cil ast
Feb 19, 2022
d672e86
Creating print_cil_ast
Darian10 Feb 19, 2022
8380748
updating cil ast
Feb 19, 2022
04a1b58
Merge branch 'master' of https://github.com/BeginnerCompilers/cool-co…
Feb 19, 2022
22f4028
Merge branch 'master' of https://github.com/BeginnerCompilers/cool-co…
Darian10 Feb 19, 2022
f5a6749
uodating visitor to cil
Feb 19, 2022
3b0dd3b
adding ErrorNode
Feb 19, 2022
629ffa2
adding ErrorNode
Feb 19, 2022
3fea7a2
base cool to cil
Feb 19, 2022
107bcc5
type name and name nodes
Feb 19, 2022
071c25a
modifying cil ast and register Object type
Feb 19, 2022
1f0fc9e
adding nodes cil ast - register IO
Feb 19, 2022
ac0b0e2
fixing issues on register COOL built-in
Feb 20, 2022
0b14d59
programNode - classDecNode
Feb 20, 2022
e6f4852
working on cool to cil visitor
Feb 20, 2022
29872f4
modifying cil ast
Feb 20, 2022
182b96a
working on cil visitor
Feb 20, 2022
0d06518
working on cil visitor
Feb 20, 2022
3aa7c4d
modifying cil ast - begin with aritmectic
Feb 20, 2022
0eeaced
arith to cil
Feb 20, 2022
8653e93
adding complNode to cil ast
Feb 21, 2022
bf6beba
atomic nodes to cil
Feb 21, 2022
f8d1fe3
call node to cil
Feb 21, 2022
2d03d23
cool to cil
Feb 21, 2022
c114563
fixing some issues
Feb 21, 2022
f99bcd8
modifying code to generate cil
Feb 22, 2022
b73b34c
fixing main
Feb 22, 2022
a68e4be
Adding instruction to code_generation
Darian10 Feb 23, 2022
0b0e40a
files
Feb 25, 2022
4d06080
Adding mips
Darian10 Feb 25, 2022
08b6092
Update Readme.md
Alexx-4 Feb 25, 2022
a35cc67
Fixing size ldata issue
Darian10 Feb 25, 2022
ccbe961
Merge branch 'master' of https://github.com/BeginnerCompilers/cool-co…
Darian10 Feb 25, 2022
1a04129
Change abort msg like tests
Darian10 Feb 25, 2022
03cb133
Update team.yml
Alexx-4 Feb 25, 2022
492ddec
Delete cells.mips
Alexx-4 Feb 25, 2022
2551b3a
Delete primes.mips
Alexx-4 Feb 25, 2022
acbe11e
rename to report
Feb 26, 2022
4fd5df2
Merge branch 'master' of https://github.com/BeginnerCompilers/cool-co…
Feb 26, 2022
66e4e4a
report
Feb 26, 2022
5789e8d
Merge branch 'master' of https://github.com/BeginnerCompilers/cool-co…
Feb 26, 2022
fe8c4db
update report
Feb 27, 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
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Verá la indicación **Some checks haven't completed yet**.

![](img/img8.png)

Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje:
Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje:

> **This branch is out-of-date with base branch**

Expand Down
Binary file added doc/Report/files/SPIM_Manual.pdf
Binary file not shown.
Binary file added doc/Report/files/compilers.pdf
Binary file not shown.
File renamed without changes.
Binary file added doc/Report/report.pdf
Binary file not shown.
215 changes: 215 additions & 0 deletions doc/Report/report.tex

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions doc/team.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
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: Alejandro Campos Matanzas
github: Alexx-4
group: C-411

- name: Darian Dominguez Alayón
github: Darian10
group: C-411
Empty file added src/cmp/__init__.py
Empty file.
62 changes: 62 additions & 0 deletions src/cmp/ast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import cmp.visitor as visitor

class Node:
def evaluate(self):
raise NotImplementedError()

class AtomicNode(Node):
def __init__(self, lex):
self.lex = lex

class UnaryNode(Node):
def __init__(self, node):
self.node = node

def evaluate(self):
value = self.node.evaluate()
return self.operate(value)

@staticmethod
def operate(value):
raise NotImplementedError()

class BinaryNode(Node):
def __init__(self, left, right):
self.left = left
self.right = right

def evaluate(self):
lvalue = self.left.evaluate()
rvalue = self.right.evaluate()
return self.operate(lvalue, rvalue)

@staticmethod
def operate(lvalue, rvalue):
raise NotImplementedError()

def get_printer(AtomicNode=AtomicNode, UnaryNode=UnaryNode, BinaryNode=BinaryNode, ):

class PrintVisitor(object):
@visitor.on('node')
def visit(self, node, tabs):
pass

@visitor.when(UnaryNode)
def visit(self, node, tabs=0):
ans = '\t' * tabs + f'\\__<expr> {node.__class__.__name__}'
child = self.visit(node.node, tabs + 1)
return f'{ans}\n{child}'

@visitor.when(BinaryNode)
def visit(self, node, tabs=0):
ans = '\t' * tabs + f'\\__<expr> {node.__class__.__name__} <expr>'
left = self.visit(node.left, tabs + 1)
right = self.visit(node.right, tabs + 1)
return f'{ans}\n{left}\n{right}'

@visitor.when(AtomicNode)
def visit(self, node, tabs=0):
return '\t' * tabs + f'\\__ {node.__class__.__name__}: {node.lex}'

printer = PrintVisitor()
return (lambda ast: printer.visit(ast))
207 changes: 207 additions & 0 deletions src/cmp/automata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
try:
import pydot
except:
pass

class State:
def __init__(self, state, final=False, formatter=lambda x: str(x), shape='circle'):
self.state = state
self.final = final
self.transitions = {}
self.epsilon_transitions = set()
self.tag = None
self.formatter = formatter
self.shape = shape

# The method name is set this way from compatibility issues.
def set_formatter(self, value, attr='formatter', visited=None):
if visited is None:
visited = set()
elif self in visited:
return

visited.add(self)
self.__setattr__(attr, value)
for destinations in self.transitions.values():
for node in destinations:
node.set_formatter(value, attr, visited)
for node in self.epsilon_transitions:
node.set_formatter(value, attr, visited)
return self

def has_transition(self, symbol):
return symbol in self.transitions

def add_transition(self, symbol, state):
try:
self.transitions[symbol].append(state)
except:
self.transitions[symbol] = [state]
return self

def add_epsilon_transition(self, state):
self.epsilon_transitions.add(state)
return self

def recognize(self, string):
states = self.epsilon_closure
for symbol in string:
states = self.move_by_state(symbol, *states)
states = self.epsilon_closure_by_state(*states)
return any(s.final for s in states)

def to_deterministic(self, formatter=lambda x: str(x)):
closure = self.epsilon_closure
start = State(tuple(closure), any(s.final for s in closure), formatter)

closures = [ closure ]
states = [ start ]
pending = [ start ]

while pending:
state = pending.pop()
symbols = { symbol for s in state.state for symbol in s.transitions }

for symbol in symbols:
move = self.move_by_state(symbol, *state.state)
closure = self.epsilon_closure_by_state(*move)

if closure not in closures:
new_state = State(tuple(closure), any(s.final for s in closure), formatter)
closures.append(closure)
states.append(new_state)
pending.append(new_state)
else:
index = closures.index(closure)
new_state = states[index]

state.add_transition(symbol, new_state)

return start

@staticmethod
def from_nfa(nfa, get_states=False):
states = []
for n in range(nfa.states):
state = State(n, n in nfa.finals)
states.append(state)

for (origin, symbol), destinations in nfa.map.items():
origin = states[origin]
origin[symbol] = [ states[d] for d in destinations ]

if get_states:
return states[nfa.start], states
return states[nfa.start]

@staticmethod
def move_by_state(symbol, *states):
return { s for state in states if state.has_transition(symbol) for s in state[symbol]}

@staticmethod
def epsilon_closure_by_state(*states):
closure = { state for state in states }

l = 0
while l != len(closure):
l = len(closure)
tmp = [s for s in closure]
for s in tmp:
for epsilon_state in s.epsilon_transitions:
closure.add(epsilon_state)
return closure

@property
def epsilon_closure(self):
return self.epsilon_closure_by_state(self)

@property
def name(self):
return self.formatter(self.state)

def get(self, symbol):
target = self.transitions[symbol]
assert len(target) == 1
return target[0]

def __getitem__(self, symbol):
if symbol == '':
return self.epsilon_transitions
try:
return self.transitions[symbol]
except KeyError:
return None

def __setitem__(self, symbol, value):
if symbol == '':
self.epsilon_transitions = value
else:
self.transitions[symbol] = value

def __repr__(self):
return str(self)

def __str__(self):
return str(self.state)

def __hash__(self):
return hash(self.state)

def __iter__(self):
yield from self._visit()

def _visit(self, visited=None):
if visited is None:
visited = set()
elif self in visited:
return

visited.add(self)
yield self

for destinations in self.transitions.values():
for node in destinations:
yield from node._visit(visited)
for node in self.epsilon_transitions:
yield from node._visit(visited)

def graph(self):
G = pydot.Dot(rankdir='LR', margin=0.1)
G.add_node(pydot.Node('start', shape='plaintext', label='', width=0, height=0))

visited = set()
def visit(start):
ids = id(start)
if ids not in visited:
visited.add(ids)
G.add_node(pydot.Node(ids, label=start.name, shape=self.shape, style='bold' if start.final else ''))
for tran, destinations in start.transitions.items():
for end in destinations:
visit(end)
G.add_edge(pydot.Edge(ids, id(end), label=tran, labeldistance=2))
for end in start.epsilon_transitions:
visit(end)
G.add_edge(pydot.Edge(ids, id(end), label='ε', labeldistance=2))

visit(self)
G.add_edge(pydot.Edge('start', id(self), label='', style='dashed'))

return G

def _repr_svg_(self):
try:
return self.graph().create_svg().decode('utf8')
except:
pass

def write_to(self, fname):
return self.graph().write_svg(fname)

def multiline_formatter(state):
return '\n'.join(str(item) for item in state)

def lr0_formatter(state):
try:
return '\n'.join(str(item)[:-4] for item in state)
except TypeError:
return str(state)[:-4]
Loading