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

Entrega final proyecto de compilacion #53

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added doc/report.pdf
Binary file not shown.
15 changes: 6 additions & 9 deletions doc/team.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
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: Abel Antonio Cruz Suarez
github: abelo98
group: C411
- name: Daniel Reynel Dominguez Ceballos
github: zondekallix
group: C411
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~=3.11
37 changes: 37 additions & 0 deletions src/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
from cool.lexer.lexer import Lexer, main
from cool.utils.LexerTokens import *
from cool.Parser.parser import Parser
from cool.semantic.semanticAnalizer import run_semantic_pipeline
from cool.cil_builder.cilAnalizer import run_code_gen_pipeline


if __name__ == '__main__':
if len(sys.argv) > 1:
input_file = sys.argv[1]
with open(input_file, encoding="utf-8") as file:
text = file.read()

lexer = main(text)
tokens = lexer.tokenize()

if (len(lexer.errors)!= 0):
for e in lexer.errors:
print(e)
raise Exception()


parser = Parser(Lexer(text))
ast = parser.parse(text)

if parser.found_error:
print(parser.errors[0])
raise Exception()

context,scope = run_semantic_pipeline(ast)
mips_output = run_code_gen_pipeline(ast,context,scope)

with open(sys.argv[2], 'w') as f:
f.write(f'{mips_output}')


190 changes: 190 additions & 0 deletions src/cool/Parser/AstNodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
class Node:
pass

class ProgramNode(Node):
def __init__(self, declarations):
self.declarations = declarations
class DeclarationNode(Node):
pass
class ExpressionNode(Node):
pass

class ClassDeclarationNode(DeclarationNode):
def __init__(self, idx, features, parent, row , column):
self.id = idx
self.parent = parent
self.features = features
self.place_holder = None
self.row = row
self.column = column


class FuncDeclarationNode(DeclarationNode):
def __init__(self, idx, params, return_type, body, row, column):
self.id = idx
self.params = params
self.type = return_type
self.body = body
self.place_holder = None
self.row = row
self.column = column

class IfNode(ExpressionNode):
def __init__(self,ifexp, thenexp,elseexp, row, column):
self.ifexp = ifexp
self.thenexp = thenexp
self.elseexp = elseexp
self.place_holder = None
self.row = row
self.column = column

class WhileNode(ExpressionNode):
def __init__(self, condition, body, row, column):
self.condition = condition
self.body = body
self.place_holder = None
self.row = row
self.column = column

class CaseNode(ExpressionNode):
def __init__(self,case,body, row, column):
self.case = case
self.body = body
self.place_holder = None
self.row = row
self.column = column

class LetNode(ExpressionNode):
def __init__(self, params, body, row, column):
self.params = params
self.body = body
self.place_holder = None
self.row = row
self.column = column

class ExpressionGroupNode(ExpressionNode):
def __init__(self, body, row, column):
self.body = body
self.place_holder = None
self.row = row
self.column = column

class AttrDeclarationNode(DeclarationNode):
def __init__(self, idx, typex, expr, row = 0, column = 0):
self.id = idx
self.type = typex
self.expr = expr
self.place_holder = None
self.row = row
self.column = column

class ParamDeclarationNode(DeclarationNode):
def __init__(self, idx, typex, row = 0, column = 0):
self.id = idx
self.type = typex
self.row = row
self.column = column

class VarDeclarationNode(ExpressionNode): #Case expr
def __init__(self, idx, typex, expr, row = 0, column = 0):
self.id = idx
self.type = typex
self.expr = expr
self.place_holder = None
self.row = row
self.column = column

class LetDeclarationNode(ExpressionNode): #Let expr
def __init__(self, idx, typex, expr, row = 0, column = 0):
self.id = idx
self.type = typex
self.expr = expr
self.place_holder = None
self.row = row
self.column = column

class AssignNode(ExpressionNode):
def __init__(self, idx, expr, row, column):
self.id = idx
self.expr = expr
self.place_holder = None
self.row = row
self.column = column

class CallNode(ExpressionNode):
def __init__(self, obj, idx, args, parent,call_type, row = 0, column = 0):
self.obj = obj
self.id = idx
self.args = args
self.parent = parent
self.place_holder = None
self.call_type = call_type
self.row = row
self.column = column

class ExpressionGroupNode(ExpressionNode):
def __init__(self, body, row, column):
self.body = body
self.place_holder = None
self.row = row
self.column = column

class AtomicNode(ExpressionNode):
def __init__(self, lex, row, column):
self.lex = lex
self.place_holder = None
self.row = row
self.column = column

class BinaryNode(ExpressionNode):
def __init__(self, tok, left, right, row, column):
self.left = left
self.right = right
self.lex = tok.value
self.row = row
self.column = column

class BinaryIntNode(BinaryNode):
pass
class BinaryBoolNode(BinaryNode):
pass

class UnaryNode(ExpressionNode):
def __init__(self,right, row, column):
self.right = right
self.place_holder = None
self.row = row
self.column = column

class StringNode(AtomicNode):
pass
class ConstantNumNode(AtomicNode):
pass
class VariableNode(AtomicNode):
pass
class InstantiateNode(AtomicNode):
pass
class BooleanNode(AtomicNode):
pass
class SelfNode(AtomicNode):
pass
class PlusNode(BinaryIntNode):
pass
class MinusNode(BinaryIntNode):
pass
class StarNode(BinaryIntNode):
pass
class DivNode(BinaryIntNode):
pass
class EqualNode(BinaryNode):
pass
class LessEqual(BinaryBoolNode):
pass
class LessNode(BinaryBoolNode):
pass
class IsVoidNode(UnaryNode):
pass
class NotNode(UnaryNode):
pass
class NegateNode(UnaryNode):
pass
Empty file added src/cool/Parser/__init__.py
Empty file.
Loading