Skip to content

Commit

Permalink
Merge branch 'master' into erick
Browse files Browse the repository at this point in the history
  • Loading branch information
erickolisveira authored Apr 27, 2020
2 parents 0fc7d66 + 8f4a81d commit 780efda
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/ELP(COM_RECURSAO).py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def p_main(p):
main : BEGIN_PROGRAM inner_statement END_PROGRAM
'''


def p_inner_statement(p):
'''
inner_statement : statement
Expand Down
12 changes: 7 additions & 5 deletions src/ExpressionLanguageParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import Visitor as vis
from ExpressionLanguageLex import *
import SintaxeAbstrata as sa
# variable - reference_variable - simple_indirect_reference_DOLAR

precedence = (
('left', 'PLUS', 'MINUS'),
Expand Down Expand Up @@ -203,6 +202,8 @@ def p_statement(p):
p[0] = sa.Statement_Return(p[1])
elif isinstance(p[1], sa.WhileStatement):
p[0] = sa.Statement_While(p[1])
elif isinstance(p[1], sa.DoWhileStatement):
p[0] = sa.Statement_Do_While(p[1])


def p_if_statement(p):
Expand Down Expand Up @@ -241,6 +242,7 @@ def p_do_statement(p):
'''
do_statement : DO statement_BLOCK_OPT WHILE expr_parentheses SEMICOLON
'''
p[0] = sa.DoWhileStatementSingle(p[2], p[4])

def p_break_statement(p):
'''
Expand Down Expand Up @@ -688,10 +690,10 @@ def p_error(p):
lex.lex()
arquivo = '''
<?php
function add($valor) {
exit (1);
return $valor;
add();
function add() {
while(true) {
return 1;
}
}
?>
'''
Expand Down
18 changes: 18 additions & 0 deletions src/SintaxeAbstrata.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def __init__(self, whilee):
self.whilee = whilee
def accept(self, Visitor):
Visitor.visitStatement_While(self)

class Statement_Do_While(Statement):
def __init__(self, dowhilee):
self.dowhilee = dowhilee
def accept(self, Visitor):
Visitor.visitStatement_Do_While(self)

class Statement_Die(Statement):
def __init__(self, die):
Expand Down Expand Up @@ -939,3 +945,15 @@ def __init__(self, statement):
self.statement = statement
def accept(self, Visitor):
Visitor.visitstatementMulSingle(self)

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

class DoWhileStatementSingle(DoWhileStatement):
def __init__(self, statementblockopt, exprparentheses):
self.statementblockopt = statementblockopt
self.exprparentheses = exprparentheses
def accept(self, Visitor):
Visitor.visitDoWhileStatementSingle(self)
12 changes: 11 additions & 1 deletion src/Visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ def visitStatement_Exit(self, statement):
def visitStatement_While(self, statement):
pp.printTab()
statement.whilee.accept(self)

def visitStatement_Do_While(self, statement):
statement.dowhilee.accept(self)
print(';')


def visitStatement_Die(self, statement):
pp.printTab()
statement.die.accept(self)
Expand Down Expand Up @@ -462,4 +466,10 @@ def visitstatementMulSingle(self, statementMul):

def visitstatementMulMul(self, statementMul):
statementMul.statement.accept(self)
statementMul.statementmul.accept(self)
statementMul.statementmul.accept(self)

def visitDoWhileStatementSingle(self, whilestatement):
print('do', end='')
whilestatement.statementblockopt.accept(self)
print('while', end='')
whilestatement.exprparentheses.accept(self)
Binary file modified src/__pycache__/ExpressionLanguageLex.cpython-38.pyc
Binary file not shown.
Binary file modified src/__pycache__/SintaxeAbstrata.cpython-38.pyc
Binary file not shown.
Binary file modified src/__pycache__/Visitor.cpython-38.pyc
Binary file not shown.
Binary file modified src/__pycache__/parsetab.cpython-38.pyc
Binary file not shown.

0 comments on commit 780efda

Please sign in to comment.