Skip to content

Commit

Permalink
Renomear regras e adicionar regra de typecast
Browse files Browse the repository at this point in the history
  • Loading branch information
erickolisveira committed Jun 8, 2020
1 parent 9f7e605 commit eb4c9d3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
13 changes: 7 additions & 6 deletions src/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ def p_main(p):
| BEGIN_PROGRAM END_PROGRAM
'''
if len(p) == 4:
p[0] = sa.Main_MainInner(p[2])
p[0] = sa.Main_MainProgram(p[2])
else:
p[0] = sa.Main_MainInner_Empty()
p[0] = sa.Main_Empty()

def p_main_program(p):
'''
main_program : inner_statement main_program
| inner_statement
'''
if len(p) == 3:
p[0] = sa.MainInner_InnerStatement_MainInner(p[1], p[2])
p[0] = sa.MainProgram_InnerStatement_Recursive(p[1], p[2])
else:
p[0] = sa.MainInner_InnerStatement(p[1])
p[0] = sa.MainProgram_InnerStatement(p[1])

def p_inner_statement(p):
'''
Expand Down Expand Up @@ -171,7 +171,8 @@ def p_typecast_operator(p):
| STRING_TYPE
| BOOL_TYPE
'''

p[0] = sa.TypeCastOp_Token(p[1])

def p_exit_statement(p):
'''
exit_statement : EXIT exit_expr
Expand Down Expand Up @@ -726,7 +727,7 @@ def p_error(p):
lex.lex()
arquivo = '''
<?php
$valor += 1;
(int) $valor;
?>
'''

Expand Down
23 changes: 8 additions & 15 deletions src/SintaxeAbstrata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ class Main(metaclass=ABCMeta):
def accept(self, Visitor):
pass

class Main_MainInner(Main):
class Main_MainProgram(Main):
def __init__(self, mainInner):
self.mainInner = mainInner
def accept(self, Visitor):
return Visitor.visitMain_MainInner(self)
return Visitor.visitMain_MainProgram(self)

class Main_MainInner_Empty(Main):
class Main_Empty(Main):
def accept(self, Visitor):
return Visitor.visitMain_MainInner_Empty(self)
return Visitor.visitMain_Empty()

#MAIN_INNER ABSTRATA E CONCRETAS
class MainInner(metaclass=ABCMeta):
@abstractmethod
def accept(self, Visitor):
pass

class MainInner_InnerStatement_MainInner(MainInner):
class MainProgram_InnerStatement_Recursive(MainInner):
def __init__(self, innerStatement, mainInner):
self.innerStatement = innerStatement
self.mainInner = mainInner
def accept(self, Visitor):
return Visitor.visitMainInner_InnerStatement_MainInner(self)
return Visitor.visitMainProgram_InnerStatement_Recursive(self)

class MainInner_InnerStatement(MainInner):
class MainProgram_InnerStatement(MainInner):
def __init__(self, innerStatement):
self.innerStatement = innerStatement
def accept(self, Visitor):
return Visitor.visitMainInner_InnerStatement(self)
return Visitor.visitMainProgram_InnerStatement(self)

class InnerStatement(metaclass = ABCMeta):
@abstractmethod
Expand Down Expand Up @@ -693,13 +693,6 @@ def __init__(self, variable,expr):
def accept(self, Visitor):
return Visitor.visitExpr_AssignExpr(self)

class Expr_AssignAmpersandExpr(Expr):
def __init__(self, variable,expr):
self.variable = variable
self.expr = expr
def accept(self, Visitor):
return Visitor.visitExpr_AssignAmpersandExpr(self)

class Expr_TypeCastOp(Expr):
def __init__(self, typeCast,expr):
self.typeCast = typeCast
Expand Down
8 changes: 4 additions & 4 deletions src/Visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

class Visitor():

def visitMain_MainInner(self, main):
def visitMain_MainProgram(self, main):
print('<?php')
pp.incrementTab()
main.mainInner.accept(self)
print('?>')

def visitMain_MainInner_Empty(self):
def visitMain_Empty(self):
print('<?php', end=' ')
print('?>', end=' ')

def visitMainInner_InnerStatement_MainInner(self, mainInner):
def visitMainProgram_InnerStatement_Recursive(self, mainInner):
mainInner.innerStatement.accept(self)
mainInner.mainInner.accept(self)

def visitMainInner_InnerStatement(self, mainInner):
def visitMainProgram_InnerStatement(self, mainInner):
mainInner.innerStatement.accept(self)

def visitInnerStatement_Statement(self, innerStatement):
Expand Down

0 comments on commit eb4c9d3

Please sign in to comment.