예제 #1
0
def p_funccall_or_exp_ident(p: yacc.YaccProduction):
    """FUNCCALL_OR_EXPRESSION : IDENT FOLLOW_IDENT"""
    node = Node(None, None, p[1], get_var_type(p[1], p.lineno(1)))

    if p[2] is None or p[2]['node'] == None:
        return

    if p[2]:
        node.value += p[2]['vec_access']
        result_type = check_type(node, p[2]['node'], p[2]['operation'],
                                 p.lineno(1))
        node = Node(node, p[2]['node'], p[2]['operation'], result_type)

        num_expressions.append((node, p.lineno(1)))
예제 #2
0
def p_funccall_or_exp_parentesis(p: yacc.YaccProduction):
    """FUNCCALL_OR_EXPRESSION : LPAREN NUMEXPRESSION RPAREN REC_UNARYEXPR REC_PLUS_MINUS_TERM OPT_REL_OP_NUM_EXPR"""
    node = p[2]['node']

    if p[4]:
        result_type = check_type(node, p[4]['node'], p[4]['operation'],
                                 p.lineno(1))
        node = Node(node, p[4]['node'], p[4]['operation'], result_type)

    if p[5]:
        result_type = check_type(node, p[5]['node'], p[5]['operation'],
                                 p.lineno(1))
        node = Node(node, p[5]['node'], p[5]['operation'], result_type)

    p[0] = {'node': node}

    num_expressions.append((node, p.lineno(1)))
예제 #3
0
def p_funccal_or_exp_string_const(p: yacc.YaccProduction):
    """FUNCCALL_OR_EXPRESSION : STRING_CONSTANT REC_UNARYEXPR REC_PLUS_MINUS_TERM OPT_REL_OP_NUM_EXPR"""
    node = Node(None, None, p[1], 'string')

    if p[2]:
        result_type = check_type(node, p[2]['node'], p[2]['operation'],
                                 p.lineno(1))
        node = Node(node, p[2]['node'], p[2]['operation'], result_type)

    if p[3]:
        result_type = check_type(node, p[3]['node'], p[3]['operation'],
                                 p.lineno(1))
        node = Node(node, p[3]['node'], p[3]['operation'], result_type)

    p[0] = {'node': node}

    num_expressions.append((node, p.lineno(1)))
예제 #4
0
def p_lvalue_ident(p: yacc.YaccProduction):
    """LVALUE : IDENT OPT_ALLOC_NUMEXP"""
    p[0] = {
        'node':
        Node(None,
             None,
             p[1] + p[2],
             result_type=get_var_type(p[1], p.lineno(1)))
    }
예제 #5
0
def p_funccall_or_exp_plus(p: yacc.YaccProduction):
    """FUNCCALL_OR_EXPRESSION : PLUS FACTOR REC_UNARYEXPR REC_PLUS_MINUS_TERM OPT_REL_OP_NUM_EXPR
                              | MINUS FACTOR REC_UNARYEXPR REC_PLUS_MINUS_TERM OPT_REL_OP_NUM_EXPR"""
    right_node = p[2]['node']
    if p[1] == '-':
        right_node.value *= -1

    if p[3]:
        result_type = check_type(p[3]['node'], right_node, p[3]['operation'],
                                 p.lineno(1))
        right_node = Node(p[3]['node'], right_node, p[3]['operation'],
                          result_type)

    if p[4]:
        result_type = check_type(p[4]['node'], right_node, p[4]['operation'],
                                 p.lineno(1))
        right_node = Node(p[4]['node'], right_node, p[4]['operation'],
                          result_type)

    num_expressions.append(right_node)
예제 #6
0
def p_numexp(p: yacc.YaccProduction):
    """NUMEXPRESSION : TERM REC_PLUS_MINUS_TERM"""
    if p[2] is None:
        p[0] = p[1]

    else:
        result_type = check_type(p[1]['node'], p[2]['node'], p[2]['operation'],
                                 p.lineno(1))
        p[0] = {
            'node':
            Node(p[1]['node'], p[2]['node'], p[2]['operation'], result_type)
        }
예제 #7
0
def p_term_unary_exp(p: yacc.YaccProduction):
    """TERM : UNARYEXPR REC_UNARYEXPR"""
    if p[2]:
        # If there's another operation being made
        result_type = check_type(p[1]['node'], p[2]['node'], p[2]['operation'],
                                 p.lineno(1))
        p[0] = {
            'node':
            Node(p[1]['node'], p[2]['node'], p[2]['operation'], result_type),
            'operation':
            p[2]['operation']
        }

    else:
        # Pass the UNARYEXPR node upwards
        p[0] = {'node': p[1]['node']}
예제 #8
0
def p_follow_ident_alloc(p: yacc.YaccProduction):
    """FOLLOW_IDENT : OPT_ALLOC_NUMEXP REC_UNARYEXPR REC_PLUS_MINUS_TERM OPT_REL_OP_NUM_EXPR"""
    node = None
    operation = ''

    if p[2]:
        node = p[2]['node']
        operation = p[2]['operation']

    if p[3]:
        if node is None:
            node = p[3]['node']
            operation = p[3]['operation']

        else:
            result_type = check_type(node, p[3]['node'], p[3]['operation'],
                                     p.lineno(0))
            node = Node(node, p[3]['node'], p[3]['operation'], result_type)

    p[0] = {'vec_access': p[1], 'node': node, 'operation': operation}
예제 #9
0
def p_rec_plus_minus(p: yacc.YaccProduction):
    """REC_PLUS_MINUS_TERM : PLUS_OR_MINUS TERM REC_PLUS_MINUS_TERM
                           | empty
    """
    if len(p) < 3:
        # Case empty
        p[0] = None

    elif p[3]:
        # Case there's another recursive operation being made
        result_type = check_type(p[2]['node'], p[3]['node'], p[3]['operation'],
                                 p.lineno(1))
        p[0] = {
            'node':
            Node(p[2]['node'], p[3]['node'], p[3]['operation'], result_type),
            'operation':
            p[1]['operation']
        }
    else:
        # Case there's no more operattions to the right
        p[0] = {'node': p[2]['node'], 'operation': p[1]['operation']}
예제 #10
0
 def summary(self):
     return '{}\n(D{})'.format(self.label, self.deadline) + Node.summary(self)
예제 #11
0
 def summary(self):
     return '{}\n(D{}|P{}/{})'.format(self.label, self.deadline, self.n_people, self.n_people_initial)\
            + Node.summary(self)
예제 #12
0
def p_factor_null(p: yacc.YaccProduction):
    """FACTOR : NULL"""
    p[0] = {'node': Node(None, None, None, 'null')}
예제 #13
0
def p_factor_string_cte(p: yacc.YaccProduction):
    """FACTOR : STRING_CONSTANT"""
    p[0] = {'node': Node(None, None, p[1], 'string')}
예제 #14
0
def p_factor_float_cte(p: yacc.YaccProduction):
    """FACTOR : FLOAT_CONSTANT"""
    p[0] = {'node': Node(None, None, p[1], 'float')}
예제 #15
0
def p_factor_int_cte(p: yacc.YaccProduction):
    """FACTOR : INT_CONSTANT"""
    p[0] = {'node': Node(None, None, p[1], 'int')}
예제 #16
0
    def _setup_rotation_data_structures(self):
        ''' For rotating the block as whole. '''
        up = Node(BlockOrientation.Up)
        right = Node(BlockOrientation.Right)
        down = Node(BlockOrientation.Down)
        left = Node(BlockOrientation.Left)

        up.next = right
        up.prev = left
        right.next = down
        right.prev = up
        down.next = left
        down.prev = right
        left.next = up
        left.prev = down

        self.block_orientations = {
            BlockOrientation.Up: up,
            BlockOrientation.Right: right,
            BlockOrientation.Down: down,
            BlockOrientation.Left: left,
        }
        ''' For the peek operation. '''
        black_top_right_corner_square = Node(
            BlockPattern.BlackTopRightCornerSquare)
        black_bottom_right_corner_square = Node(
            BlockPattern.BlackBottomRightCornerSquare)
        black_bottom_left_corner_square = Node(
            BlockPattern.BlackBottomLeftCornerSquare)
        black_top_left_corner_square = Node(
            BlockPattern.BlackTopLeftCornerSquare)
        white_square = Node(BlockPattern.WhiteSquare)
        black_square = Node(BlockPattern.BlackSquare)

        white_square.next = white_square
        white_square.prev = white_square
        black_square.next = black_square
        black_square.prev = black_square
        black_top_right_corner_square.next = black_bottom_right_corner_square
        black_top_right_corner_square.prev = black_top_left_corner_square
        black_bottom_right_corner_square.next = black_bottom_left_corner_square
        black_bottom_right_corner_square.prev = black_top_right_corner_square
        black_bottom_left_corner_square.next = black_top_left_corner_square
        black_bottom_left_corner_square.prev = black_bottom_right_corner_square
        black_top_left_corner_square.next = black_top_right_corner_square
        black_top_left_corner_square.prev = black_bottom_left_corner_square

        self.face_orientations = {
            BlockPattern.BlackTopRightCornerSquare:
            black_top_right_corner_square,
            BlockPattern.BlackBottomRightCornerSquare:
            black_bottom_right_corner_square,
            BlockPattern.BlackBottomLeftCornerSquare:
            black_bottom_left_corner_square,
            BlockPattern.BlackTopLeftCornerSquare:
            black_top_left_corner_square,
            BlockPattern.BlackSquare: black_square,
            BlockPattern.WhiteSquare: white_square,
        }