Skip to content

Commit

Permalink
Ajustar conflitos de git pull
Browse files Browse the repository at this point in the history
  • Loading branch information
erickolisveira committed Jun 4, 2020
2 parents aaf755d + 0f05b69 commit 15bb34b
Show file tree
Hide file tree
Showing 46 changed files with 183 additions and 2,222 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src/__pycache__/
src/parser.out
src/parsetab.py
.vscode
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Compilador na linguagem PHP
Link da documentação : https://www.php.net/manual/pt_BR/language.basic-syntax.comments.php
## Compilador para a linguagem PHP

Link POO Python: https://www.dcc.ufrj.br/~fabiom/mab225/pythonoo.pdf
***

## Bibliotecas
1. [PLY (Python Lex-Yacc)](https://www.dabeaz.com/ply/ply.html)


## Documentos de apoio
1. [Linguagem sintática](https://www.php.net/manual/pt_BR/language.basic-syntax.comments.php)
2. [OO Python](https://www.dcc.ufrj.br/~fabiom/mab225/pythonoo.pdf)
72 changes: 40 additions & 32 deletions src/ExpressionLanguageParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,53 +212,61 @@ def p_statement(p):
elif isinstance(p[1], sa.ForStatement):
p[0] = sa.Statement_For(p[1])

def p_global_statement(p):
'''
global_statement : GLOBAL global_var statement_COLON_GLOBAL
| GLOBAL global_var
'''
if len(p) == 3:
p[0] = sa.GlobalStatement_Single(p[2])
else:
p[0] = sa.GlobalStatement_Mul(p[2], p[3])



def p_if_statement(p):
'''
if_statement : statement_if if_statement_complement
| statement_if
'''
if len(p)==3:
p[0] = sa.IfStatement_Complement(p[1],p[2])
else:
p[0] = sa.IfStatement_Single(p[1])

if_statement : statement_if
| statement_if statement_else
| statement_if statement_elseif
| statement_if statement_elseif statement_else
'''
if len(p)== 2:
p[0] = sa.IfStatement_statement_if(p[1])
elif len(p) == 3 and isinstance(p[2], sa.StatementElse):
p[0] = sa.IfStatement_statementIf_Else(p[1],p[2])
elif len(p)== 3 and isinstance(p[2], sa.StatementElseIf):
p[0] = sa.IfStatement_StatementIf_Elseif(p[1],p[2])
elif len(p)== 4:
p[0] = sa.IfStatement_StmIf_Elseif_Else(p[1],p[2],p[3])

def p_statement_if(p):
'''
statement_if : IF expr_parentheses statement_BLOCK_OPT
statement_if : IF expr_parentheses statement_BLOCK_OPT statement_if
| IF expr_parentheses statement_BLOCK_OPT
'''
if len(p) ==4:
p[0] = sa.StatementIf_ExprParen(p[2],p[3])
if len(p) ==5:
p[0] = sa.StatementIf_Mul(p[2],p[3],p[4])
elif len(p) ==4:
p[0] = sa.StatementIf_Single(p[2],p[3])

def p_if_statement_complement(p):
def p_statement_elseif(p):
'''
if_statement_complement : statement_elseif
| statement_else
statement_elseif : ELSEIF expr_parentheses statement_BLOCK_OPT statement_elseif
| ELSEIF expr_parentheses statement_BLOCK_OPT
|
'''
p[0] = sa.IfStatement_Else(p[1])
if len(p) == 5:
p[0] = sa.StatementElseIf_Mul(p[2],p[3],p[4])
elif len(p) == 4:
p[0] = sa.StatementElseIf_Single(p[2],p[3])

def p_statement_else(p):
'''
statement_else : ELSE statement_BLOCK_OPT
'''
if len(p)==3:
p[0] = sa.StatementElse_Else(p[2])

if len(p) == 3:
p[0] = sa.StatementElse_Single(p[2])

def p_statement_elseif(p):
def p_global_statement(p):
'''
statement_elseif : ELSEIF expr_parentheses statement_BLOCK_OPT
global_statement : GLOBAL global_var statement_COLON_GLOBAL
| GLOBAL global_var
'''
if len(p) == 3:
p[0] = sa.GlobalStatement_Single(p[2])
else:
p[0] = sa.GlobalStatement_Mul(p[2], p[3])


def p_while_statement(p):
'''
Expand Down Expand Up @@ -359,7 +367,7 @@ def p_statement_COLON_GLOBAL(p):
if len(p) == 3:
p[0] = sa.GlobalVarMul_Single(p[2])
else:
p[0] = sa.GloballVarMul_Mul(p[2], p[3])
p[0] = sa.GlobalVarMul_Mul(p[2], p[3])

def p_ampersand_variable(p):
'''
Expand Down
21 changes: 13 additions & 8 deletions src/SemanticVisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

import SintaxeAbstrata as sa

def coercion(type1, type2):
if (type1 in st.Number and type2 in st.Number):
if (type1 == st.FLOAT or type2 == st.FLOAT):
return st.FLOAT
else:
return st.INT
else:
return None

def isValidNumber(number):
try:
if(number in st.Number and int(number) or float(number) ):
return True
except ValueError:
return False

def coercion(type1, type2):
if (type1 in st.Number and type2 in st.Number):
if (type1 == st.FLOAT or type2 == st.FLOAT):
return st.FLOAT
return st.INT
return None

class SemanticVisitor(AbstractVisitor):

Expand Down
96 changes: 67 additions & 29 deletions src/SintaxeAbstrata.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,65 +201,103 @@ def __init__(self, expr):
def accept(self, Visitor):
return Visitor.visitExprParentheses_Expr(self)


class Else(metaclass = ABCMeta):
class IfStatement(metaclass = ABCMeta):
@abstractmethod
def accept(self,Visitor):
def accept(self, Visitor):
pass

class IfStatementComplement(metaclass = ABCMeta):
@abstractmethod
def accept(self,Visitor):
pass
class IfStatement_statement_if(IfStatement):
def __init__(self, statement_if):
self.statement_if = statement_if
def accept(self, Visitor):
Visitor.visitIfStatement_statement_if(self)

class IfStatement_Else(IfStatementComplement):
def __init__(self, statement_else):
self.statement_else = statement_else
class IfStatement_statementIf_Else(IfStatement):
def __init__(self, statement_if, statement_else):
self.statement_if = statement_if
self.statement_else = statement_else
def accept(self, Visitor):
return Visitor.visitIfStatemnet_Else(self)

class StatementElse(metaclass = ABCMeta):
@abstractmethod

class IfStatement_StatementIf_Elseif(IfStatement):
def __init__ (self,statement_if, statement_elseif):
self.statement_if = statement_if
self.statement_elseif = statement_elseif
def accept(self, Visitor):
pass
Visitor.visitIfStatement_StatementIf_Elseif(self)

class IfStatement_StmIf_Elseif_Else(IfStatement):
def __init__(self,statement_if,statement_elseif,statement_else):
self.statement_if = statement_if
self.statement_elseif = statement_elseif
self.statement_else = statement_else

class StatementElse_Else(StatementElse):
def __init__(self, statementBlockOpt):
self.statementBlockOpt = statementBlockOpt
def accept(self, Visitor):
return Visitor.visitStatementElse_Else(self)

class IfStatement(metaclass=ABCMeta):
@abstractmethod
def accept(self, Visitor):
pass
@abstractmethod
def accept(self, Visitor):
Visitor.visitIfStatement_Stm_If_Elseif_Else(self)

class IfStatement_Complement(IfStatement):
def __init__(self,statement_if,if_statement_complement):
class StatementIf_Mul(IfStatement):
def __init__(self, expr_parentheses,statement_BLOCK_OPT,statement_if):
self.expr_parentheses = expr_parentheses
self.statement_BLOCK_OPT=statement_BLOCK_OPT
self.statement_if = statement_if
self.if_statement_complement = if_statement_complement

def accept(self,Visitor):
return Visitor.visitIfStatement_Complement(self)

class IfStatement_Single(IfStatement):
def __init__(self, statementIf):
self.statementIf = statementIf
class StatementIf_Single(IfStatement):
def __init__(self, expr_parentheses,statement_BLOCK_OPT):
self.expr_parentheses = expr_parentheses
self.statement_BLOCK_OPT=statement_BLOCK_OPT
def accept(self,Visitor):
Visitor.visitStatementIf_Single(self)

class ElseIf_ifStatement(metaclass = ABCMeta):
@abstractmethod
def accept(self, Visitor):
return Visitor.visitIfStatement_Single(self)

class StatementIf(metaclass=ABCMeta):
class StatementElseIf(metaclass = ABCMeta):
@abstractmethod
def accept(self, Visitor):
pass

class StatementIf_ExprParen(StatementIf):
class StatementElseIf_Mul(StatementElseIf):
def __init__(self, expr_parentheses,statement_BLOCK_OPT, statement_elseif):
self.expr_parentheses = expr_parentheses
self.statement_BLOCK_OPT = statement_BLOCK_OPT
self.statement_elseif = statement_elseif
def accept(self, Visitor):
Visitor.visitStatementElseIf_Mul(self)

class StatementElseIf_Single(StatementElseIf):
def __init__(self, expr_parentheses,statement_BLOCK_OPT):
self.expr_parentheses = expr_parentheses
self.statement_BLOCK_OPT=statement_BLOCK_OPT
self.expr_parentheses = expr_parentheses
self.statement_BLOCK_OPT = statement_BLOCK_OPT

def accept(self, Visitor):
Visitor.visitStatementElseIf_Single(self)


class StatementElse(metaclass = ABCMeta):
@abstractmethod
def accept(self, Visitor):
pass

class StatementElse_Single(StatementElse):
def __init__(self, statement_BLOCK_OPT):
self.statement_BLOCK_OPT = statement_BLOCK_OPT

def accept(self,Visitor):
return Visitor.visitStatementIf_ExprParen(self)



class funcDecStatement_Function(FuncDecStatement):
def __init__(self, fds_id, fds_parameter, fds_statements):
self.fds_id = fds_id
Expand Down
71 changes: 52 additions & 19 deletions src/Visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,6 @@ def visitStatement_Return(self, statement):
pp.printTab()
statement._return.accept(self)

def visitStatement_If(self, statement):
pp.printTab()
statement._if.accept(self)

def visitStatementElse_Else(self, statementElse):
pp.printTab()
print('else',end='')
statementElse.statementBlockOpt.accept(self)


def visitStatement_Exit(self, statement):
pp.printTab()
statement.exit.accept(self)
Expand Down Expand Up @@ -206,25 +196,68 @@ def visitStatement_For(self, statement):
pp.printTab()
statement._for.accept(self)

def visitIfStatement_Single(self, ifStatement):
ifStatement.statementIf.accept(self)
def visitStatement_If(self, statement):
statement._if.accept(self)

def visitIfStatement_Complement(self, ifStatement):
ifStatement.statement_if.accept(self)
ifStatement.if_statement_complement.accept(self)
def visitIfStatement_statement_if(self, IfStatement):
IfStatement.statement_if.accept(self)

def vistIfStatement_statementIf_Else(self, statementIfElse):
statementIfElse.statement_if.accept(self)
statementIfElse.statement_else.accept(self)

def visitStatementIf_ExprParen(self, statement_if):
def visitIfStatement_StatementIf_Elseif(self, statementIfElseif):
statementIfElseif.statement_if.accept(self)
statementIfElseif.statement_elseif.accept(self)

def visitIfStatement_Stm_If_Elseif_Else(self, statementIfElseifElse):
statementIfElseifElse.statement_if.accept(self)
statementIfElseifElse.statement_elseif.accept(self)
statementIfElseifElse.statement_else.accept(self)

def visitStatementIf_Mul(self, statementIfMul):
pp.printTab()
print('if',end='')
statement_if.expr_parentheses.accept(self)
statement_if.statement_BLOCK_OPT.accept(self)
statementIfMul.expr_parentheses.accept(self)
statementIfMul.statement_BLOCK_OPT.accept(self)
statementIfMul.statement_if.accept(self)

def visitStatementIf_Single(self, statementIfSingle):
pp.printTab()
print('if',end='')
statementIfSingle.expr_parentheses.accept(self)
statementIfSingle.statement_BLOCK_OPT.accept(self)

def visitStatementElseIf_Mul(self, statementElseIfMul):
pp.printTab()
print('elseif',end='')
statementElseIfMul.expr_parentheses.accept(self)
statementElseIfMul.statement_BLOCK_OPT.accept(self)
statementElseIfMul.statement_elseif.accept(self)

def visitStatementElseIf_Single(self, statementElseIfSingle):
pp.printTab()
print('elseif',end='')
statementElseIfSingle.expr_parentheses.accept(self)
statementElseIfSingle.statement_BLOCK_OPT.accept(self)


def visitStatementElse_Single(self, statementElse):
pp.printTab()
print('else',end='')
statementElse.statement_BLOCK_OPT.accept(self)

def visitExprParentheses_Expr(self, exprParentheses_Expr):
print('(',end='')
exprParentheses_Expr.expr.accept(self)
print(')',end='')

def visitIfStatemnet_Else(self, ifStatementElse):
def visitIfStatement_Else(self, ifStatementElse):
ifStatementElse.statement_else.accept(self)

def visitIfStatement_ElseIf(self, ifStatementElseif):
ifStatementElseif.statement_elseif.accept(self)


def visitExpr_Minus_Expr1(self, expr):
print('-', end='')
Expand Down
10 changes: 0 additions & 10 deletions utility/Análise léxica - JAVA/.classpath

This file was deleted.

Loading

0 comments on commit 15bb34b

Please sign in to comment.