Example #1
0
def p_Printing(p):
    '''Printing : TkPrintln ExpAux
                | TkPrint ExpAux
                | TkPrintln TkString TkConcat Concat
                | TkPrint TkString TkConcat Concat
                | TkPrintln ExpAux TkConcat Concat
                | TkPrint ExpAux TkConcat Concat
                | TkPrintln TkString
                | TkPrint TkString'''
    #print("Regla15")
    if len(p) == 3:
        if type(p[2]) is str:
            p[0] = Node(p[1], p[1], [Node("String", p[2])])
        else:
            p[0] = Node(p[1], p[1], [Node("Exp", "Exp", [p[2]])])
    else:
        if type(p[2]) is str:
            p[0] = Node(
                p[1], p[1],
                [Node("String", p[2]),
                 Node("Concat", "Concat", [p[4]])])
        else:
            p[0] = Node(
                p[1], p[1],
                [Node("Exp", "Exp", [p[2]]),
                 Node("Concat", "Concat", [p[4]])])
Example #2
0
def p_Asig(p):
    '''Asig : TkId TkAsig ExpAux'''
    #print("Regla13")
    # simbol_table.setValue(p[1], Node("Exp", "Exp", [p[3]]))
    p[0] = Node(
        "Asig", "Asig",
        [Node("Ident", p[1]), Node("Exp", "Exp", [p[3]])])
Example #3
0
def p_SingleTypeDeclaration(p):
    '''SingleTypeDeclaration : TkId TkComma SingleTypeDeclaration
                             | TkId TkComma TkId TkTwoPoints IdType'''
    if len(p) == 4:
        p[0] = [Node("Ident", p[1])] + p[3]
    else:
        p[0] = [Node("Ident", p[1]), Node("Ident", p[3])]
def p_InstSequence(p):
    '''InstSequence : TkSemicolon InstructionLine InstSequence
                    | TkSemicolon InstructionLine'''
    if (len(p) == 4):
        p[0] = Node("InstSequence", "Sequence", [p[2], p[3]])
    else:
        p[0] = Node("InstSequence", "Sequence", [p[2]])
def p_IdList(p):
    '''IdList : TkId TkComma IdList
              | TkId'''
    #print("Regla8")
    if (len(p) == 4):
        p[0] = Node("Ident", p[1], [p[3]])
    else:
        p[0] = Node("Ident", p[1])
def p_DeclarationSequence(p):
    '''DeclarationSequence : TkSemicolon VarDeclaration DeclarationSequence
                           | TkSemicolon VarDeclaration'''
    #print("Regla4")
    if (len(p) == 4):
        p[0] = Node("DeclarationSequence", "Sequence", [p[1], p[2]])
    else:
        p[0] = Node("DeclarationSequence", "Sequence", [p[1]])
Example #7
0
def p_Body(p):
    '''Body : ExpAux TkArrow Instructions GuardList
            | ExpAux TkArrow Instructions'''
    #print("Regla15")
    if len(p) == 5:
        p[0] = Node("Guard", "Guard", [Node("Exp", "Exp", [p[1]])] + p[3] + [p[4]])
    else:
        p[0] = Node("Guard", "Guard", [Node("Exp", "Exp", [p[1]])] + p[3])
def p_DeclareLines(p):
    '''DeclareLines : VarDeclaration DeclarationSequence
                    | VarDeclaration'''
    #print("Regla3")
    if (len(p) == 3):
        p[0] = Node("DeclareLines", "Declare", [p[1], p[2]])
    else:
        p[0] = Node("DeclareLines", "Declare", [p[1]])
def p_MultipleTypeDeclaration(p):
    '''MultipleTypeDeclaration : TkId TkComma MultipleTypeDeclaration TkComma IdType
                               | TkId TkTwoPoints IdType'''
    #print("Regla6")
    if (len(p) == 6):
        p[0] = Node("Ident", p[1], [p[3]])
    else:
        p[0] = Node("Ident", p[1])
Example #10
0
def p_GuardList(p):
    '''GuardList : TkGuard ExpAux TkArrow Instructions GuardList
                 | TkGuard ExpAux TkArrow Instructions'''
    #print("Regla16")
    if len(p) == 6:
        p[0] = Node("Guard", "Guard", [Node("Exp", "Exp", [p[2]])] + p[4] + [p[5]])
    else:
        p[0] = Node("Guard", "Guard", [Node("Exp", "Exp", [p[2]])] + p[4])
def p_Function(p):
    '''Function : TkAtoi TkOpenPar AbsValue TkClosePar
                | TkSize TkOpenPar AbsValue TkClosePar
                | TkMax TkOpenPar AbsValue TkClosePar
                | TkMin TkOpenPar AbsValue TkClosePar'''
    #print("Regla19")
    #print(p[3].value)
    ast.setNode(Node("Function", p[1], [p[3]]))
    p[0] = Node("Function", p[1], [p[3]])
def p_GuardList(p):
    '''GuardList : TkOBracket TkCBracket ExpAux TkArrow Instructions GuardList
                 | TkOBracket TkCBracket ExpAux TkArrow Instructions'''
    #print("Regla16")
    if len(p) == 7:
        p[0] = Node("Guard", "Guard",
                    [Node("Exp", "Exp", [p[3]])] + p[5] + [p[6]])
    else:
        p[0] = Node("Guard", "Guard", [Node("Exp", "Exp", [p[3]])] + p[5])
Example #13
0
 def __init__(self, conditionProgram, trueProgram, lineno=0):
     self.lineno = lineno
     self.conditionProgram = conditionProgram
     Node.__init__(self, [conditionProgram, trueProgram])
     conditionProgramType = self.conditionProgram.getOperationType()
     if conditionProgramType is not TypeBooleanNode:
         errorList.append(
             f"NotBooleanException at line {self.lineno} : Must be a boolean for a Loop"
         )
def p_ProgramBlock(p):
    '''ProgramBlock : TkOBlock Declaration Instructions TkCBlock
                    | TkOBlock Instructions TkCBlock'''
    #print("Regla1")
    if len(p) == 5:
        p[0] = Node("ProgramBlock", "Block", [p[2]] + p[3])
    else:
        p[0] = Node("ProgramBlock", "Block", p[2])
    p[0].printTree("")
Example #15
0
def p_ProgramBlock(p):
    '''ProgramBlock : TkOBlock TkDeclare DeclareLines Instructions TkCBlock
                    | TkOBlock Instructions TkCBlock'''
    #print("Regla1")
    if len(p) == 6:
        p[0] = Node("ProgramBlock", "Block",
                    [Node("Declare", "Declare", [p[3]])] + p[4])
    else:
        p[0] = Node("ProgramBlock", "Block", p[2])
Example #16
0
def p_MultipleTypeDeclaration(p):
    '''MultipleTypeDeclaration : TkId TkComma MultipleTypeDeclaration TkComma IdType
                               | TkId TkTwoPoints IdType'''
    #print("Regla6")
    if (len(p) == 6):

        p[0] = [Node("Ident", p[1])] + p[3]
    else:
        simbol_table.setSimbol(Simbol(p[1], p[3]))
        p[0] = [Node("Ident", p[1])]
def p_InstSequence(p):
    '''InstSequence : TkSemicolon InstructionLine InstSequence
                    | TkSemicolon InstructionLine'''
    #print("Regla11")
    if (len(p) == 4):
        ast.setNode(Node("InstSequence", "Sequence", [p[2], p[3]]))
        p[0] = Node("InstSequence", "Sequence", [p[2], p[3]])
    else:
        ast.setNode(Node("InstSequence", "Sequence", [p[2]]))
        p[0] = Node("InstSequence", "Sequence", [p[2]])
Example #18
0
def p_factor_func(p):
    """
    factor  : SYS_FUNCT
            | ID  LP  args_list  RP
            | SYS_FUNCT  LP  args_list  RP
    """
    if len(p) == 2:
        p[0] = Node('factor-func', p.lexer.lineno, p[1])
    else:
        p[0] = Node('factor-func', p.lexer.lineno, p[1], p[3])
Example #19
0
    def __init__(self, value, lineno=0):
        valueType = value.getOperationType()
        self.lineno = lineno

        if valueType is not TypeShapeNode:
            errorList.append(
                f'InvalidTypeException at line {self.lineno} : Must be a shape to draw instead of {createErrorStringFromClassName(valueType)}'
            )

        Node.__init__(self, [value])
def p_MultipleTypeDeclaration(p):
    '''MultipleTypeDeclaration : TkId TkComma MultipleTypeDeclaration TkComma IdType
                               | TkId TkTwoPoints IdType'''
    #print("Regla6")
    if (len(p) == 6):
        ast.setNode(Node("Ident", p[1]))
        p[0] = [Node("Ident", p[1])] + p[3]
    else:
        ast.setNodeWithSimbol(Node("Ident", p[1]), Simbol(p[1], None, None))
        p[0] = [Node("Ident", p[1])]
        print(p[3])
Example #21
0
def p_proc_stmt(p):
    """
    proc_stmt :  ID
              |  ID  LP  args_list  RP
              |  SYS_PROC
              |  SYS_PROC  LP  expression_list  RP
              |  kREAD  LP  factor  RP
    """
    if len(p) == 2:
        p[0] = Node("proc_stmt-simple", p.lexer.lineno, p[1])
    elif len(p) == 5:
        p[0] = Node("proc_stmt", p.lexer.lineno, p[1], p[3])
def p_Value(p):
    '''Value : TkMinus AbsValue
             | TkMinus Function
             | AbsValue
             | Function'''
    #print("Regla18")
    if len(p) == 3:
        ast.setNode(Node("Value", "UnaryMinus", [p[2]]))
        p[0] = Node("Value", "UnaryMinus", [p[2]])
    else:
        #print(p[1].value)
        p[0] = p[1]
Example #23
0
    def __init__(self, operation, operandes, lineno):
        Node.__init__(self, operandes)
        self.operandes = operandes
        self.operation = operation
        self.lineno = lineno

        constraints = BinaryOperation.operationTable[self.operation][1]
        op = self.getOperandeType()
        if op not in constraints:
            errorList.append(
                f'InvalidOperandeException at line {self.lineno} : For binary operation \'{self.operation}\' use \'{createErrorStringFromClassName(constraints)}\' instead of \'{createErrorStringFromClassName([op])}\''
            )
def p_AbsValue(p):
    '''AbsValue : TkNum
                | TkId
                | TkTrue
                | TkFalse'''
    #print("Regla20")
    if type(p[1]) is int:
        p[0] = Node("Literal", p[1])
    else:
        if p[1] == 'true' or p[1] == 'false':
            p[0] = Node("Literal", p[1])
        else:
            p[0] = Node("Ident", p[1])
Example #25
0
def p_expr(p):
    """
    expr :  expr  ADD  term
         |  expr  SUBTRACT  term
         |  expr  kOR  term
         |  term
    """
    if len(p) == 2:
        p[0] = p[1]
    elif p[2] == '+':
        p[0] = Node("expr-ADD", p.lexer.lineno, p[1], p[3])
    elif p[2] == '-':
        p[0] = Node("expr-SUBTRACT", p.lexer.lineno, p[1], p[3])
    elif p[2] == 'or':
        p[0] = Node("expr-OR", p.lexer.lineno, p[1], p[3])
Example #26
0
def p_var_decl_list(p):
    '''var_decl_list :  var_decl_list  var_decl  
                    |  var_decl'''
    if len(p) == 3:
        p[0] = Node("var_decl_list", p.lexer.lineno, p[1], p[2])
    else:
        p[0] = p[1]
Example #27
0
    def __init__(self, tokenVariableName, value, lineno=0):
        variableName = tokenVariableName.variableName
        self.lineno = lineno
        if variableName not in variablesTypes.keys():
            errorList.append(
                f'UndeclaredVariableException at line {self.lineno} : Variable \'{variableName}\' not declared'
            )
        else:
            valueType = value.getOperationType()
            variableType = variablesTypes[variableName]
            if valueType != variableType:
                errorList.append(
                    f'InvalidTypeException at line {self.lineno} : Variable \'{variableName}\' is of type \'{createErrorStringFromClassName(variableType)}\' instead of \'{createErrorStringFromClassName(valueType)}\''
                )

        Node.__init__(self, [tokenVariableName, value])
Example #28
0
def p_expression(p):
    """
    expression :  expression  GE  expr
               |  expression  GT  expr
               |  expression  LE  expr
               |  expression  LT  expr
               |  expression  EQUAL  expr
               |  expression  UNEQUAL  expr
               |  expr
    """
    if len(p) == 4:
        p[0] = Node("expression", p.lexer.lineno, p[1], p[2], p[3])
    elif len(p) == 2:
        p[0] = Node("expression", p.lexer.lineno, p[1])
    else:
        raise Exception
Example #29
0
def p_para_decl_list(p):
    '''para_decl_list :  para_decl_list  SEMICON  para_type_list 
                    | para_type_list'''
    if len(p) == 4:
        p[0] = Node("para_decl_list", p.lexer.lineno, p[1], p[3])
    else:
        p[0] = p[1]
Example #30
0
def p_stmt_list(p):
    """
    stmt_list :  stmt_list  stmt  SEMICON
              |  empty
    """
    if len(p) == 4:
        p[0] = Node("stmt_list", p.lexer.lineno, p[1], p[2])