def p_term_not_var_oper(p): 'term_bool : NOT var_oper' p[0] = ['not ' + p[2][0], 'BOOL'] if not esBool(p[2][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_bool_v2ov2(p): 'term_bool : var_oper OR var_oper' p[0] = [p[1][0] + ' or ' + p[3][0], 'BOOL'] if not esBool(p[1][1]) or not esBool(p[3][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_bool_expr_v2av2(p): 'exp_bool : var_oper AND var_oper' p[0] = [p[1][0] + ' and ' + p[3][0], 'BOOL'] if not esBool(p[3][1]) or not esBool(p[1][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_exp_cadena_concat_2(p): 'exp_cadena : exp_cadena PLUS var_oper' p[0] = [p[1][0] + ' + ' + p[3][0], 'STRING'] if not esString(p[3][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_loop_while(p): 'loop : WHILE LPAREN control_cond_term RPAREN bloque' p[0] = ['while(' + p[3][0] + ')\n ' + find_and_replace(p[5][0]), 'ND'] if not esBool(p[3][1]): pass raise SemanticException('LOOP', p.lineno(1), p.lexpos(1))
def p_var_asig_pp_base(p): 'var_asig : MASMAS var_asig_l ' p[0] = ['++' + toStrIfInt(p[2][0]), p[2][1]] if not esNumber(p[2][1]): pass raise SemanticException('NODEFINIDA', p.lineno(1), p.lexpos(1))
def p_factor_pp_var_op(p): 'factor : MASMAS var_oper' p[0] = ['++' + p[2][0], p[2][1]] if not esNumber(p[2][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_factor_m_var_oper(p): 'factor : MINUS var_oper' p[0] = ['-' + p[2][0], 'NUMBER_FLOAT'] if not esNumber(p[2][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_factor_var_op__exp(p): 'factor : var_oper ELEVADO sigexp' p[0] = [p[1][0] + ' ^' + toStrIfInt(p[3][0]), tipoNumber(p[1][1], p[3][1])] if not esNumber(p[1][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_factor_var_op_mm(p): 'factor : var_oper LESSLESS' p[0] = [toStrIfInt(p[1][0]) + '--', p[1][1]] if not esNumber(p[1][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_exp_arit_emv2(p): 'exp_arit : exp_arit MINUS var_oper' p[0] = [p[1][0] + ' - ' + p[3][0], tipoNumber(p[1][1], p[3][1])] if not esNumber(p[3][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_factor_mm_var_op(p): 'factor : LESSLESS var_oper' p[0] = ['--' + toStrIfInt(p[2][0]), p[2][1]] if not esNumber(p[2][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_var_asig_sacar(p): 'var_asig : var_asig_l SACAR valores' p[0] = [p[1][0] + '-=' + toStrIfInt(p[3][0]), tipoNumber(p[1][1], p[3][1])] if not esNumber(p[1][1]) or not esNumber(p[3][1]): pass raise SemanticException('NODEFINIDA', p.lineno(1), p.lexpos(1))
def p_var_asig_base_pp(p): 'var_asig : var_asig_l MASMAS' p[0] = [toStrIfInt(p[1][0]) + '++', p[1][1]] if not esNumber(p[1][1]): pass raise SemanticException('NODEFINIDA', p.lineno(1), p.lexpos(1))
def p_exp_var_op(p): 'exp : var_oper' p[0] = [p[1][0], p[1][1]] if not esNumber(p[1][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_factor_var_op_pp(p): 'factor : var_oper MASMAS' p[0] = [p[1][0] + '++', p[1][1]] if not esNumber(p[1][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_var_member_reg_item_rec(p): 'var_member : PUNTO VARIABLE var_member' p[0] = ['.' + p[2] + p[3][0], 'ND'] if estaReg(p[2]) == 'ND': pass raise SemanticException('REGISTRO', p.lineno(2), p.lexpos(2))
def p_funcion_ret_string_2(p): 'func_ret_cadena : CAPITALIZAR LPAREN operador_ternario RPAREN' p[0] = ['capitalizar(' + p[3][0] + ')', 'STRING'] if not esString(p[3][1]): pass raise SemanticException('CAPITALIZAR', p.lineno(3), p.lexpos(3))
def p_funcion_ret_int_length(p): 'func_ret_int : LENGTH LPAREN valores RPAREN' p[0] = ['length(' + p[3][0] + ')', 'NUMBER_INT'] if (not esString(p[3][1]) and not esVector(p[3][1])): pass raise SemanticException('LENGTH', p.lineno(3), p.lexpos(3))
def p_ifSinElse(p): 'ifelse : IF LPAREN control_cond_term RPAREN bloque' p[0] = ['If(' + p[3][0] + ')\n ' + find_and_replace(p[5][0]), 'ND'] if not esBool(p[3][1]): pass raise SemanticException('IF', p.lineno(1), p.lexpos(1))
def p_term_v2mv2(p): 'term : var_oper arit_oper_2 var_oper' p[0] = [p[1][0] + p[2][0] + p[3][0], tipoNumber(p[1][1], p[3][1])] if not esNumber(p[1][1]) or not esNumber(p[3][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_base_paren_var_oper(p): 'base : LPAREN var_oper RPAREN' p[0] = ['(' + p[2][0] + ')', p[2][1]] if not esNumber(p[2][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_operador_ternario_4(p): 'operador_ternario : comparacion INTERROGACION valores DOSPUNTOS operador_ternario' p[0] = [p[1][0] + ' ? ' + p[3][0] + ':' + p[5][0], p[3][1]] if not esBool(p[1][1]) or (p[3][1] != p[5][1] and not (esNumber(p[3][1]) and esNumber(p[5][1])) and p[3][1] != 'CUALQUIER_TIPO' and p[5][1] != 'CUALQUIER_TIPO'): raise SemanticException('OPTERNARIO', p.lineno(1), p.lexpos(1))
def p_funcion_ret_bool_f(p): 'func_ret_bool : COLINEALES LPAREN valores COMA valores RPAREN ' p[0] = ['colineales(' + p[3][0] + ',' + p[5][0] + ')', 'BOOL'] if (not esNumber(tipo(p[3][1])) and p[3][1] != "VECTOR_VACIO") or (not esNumber(tipo(p[5][1])) and p[5][1] != "VECTOR_VACIO"): pass raise SemanticException('COLINEALES', p.lineno(2), p.lexpos(2))
def p_loop_do(p): 'loop : DO bloque WHILE LPAREN control_cond_term RPAREN PUNTOYCOMA' p[0] = [ 'do\n ' + find_and_replace(p[2][0]) + '\nwhile(' + p[5][0] + ');', 'ND' ] if not esBool(p[5][1]): pass raise SemanticException('LOOP', p.lineno(1), p.lexpos(1))
def p_var_asig_agregar(p): 'var_asig : var_asig_l AGREGAR valores' p[0] = [p[1][0] + '+=' + toStrIfInt(p[3][0]), tipoNumber(p[1][1], p[3][1])] if (esNumber(p[1][1]) and esNumber(p[1][1])) or (p[1][1] == "STRING" and p[3][1] == "STRING"): pass else: pass raise SemanticException('NODEFINIDA', p.lineno(1), p.lexpos(1))
def p_for_main(p): 'for : FOR LPAREN form_term PUNTOYCOMA form_term_2 PUNTOYCOMA form_term RPAREN bloque' p[0] = [ 'for(' + p[3][0] + ';' + p[5][0] + ';' + p[7][0] + ')\n ' + find_and_replace(p[9][0]), 'ND' ] if not esBool(p[5][1]): pass raise SemanticException('LOOP', p.lineno(1), p.lexpos(1))
def p_exp_arit_v2mv2(p): 'exp_arit : var_oper MINUS var_oper' p[0] = [ p[1][0] + ' - ' + toStrIfInt(p[3][0]), tipoNumber(p[1][1], p[3][1]) ] if not esNumber(p[1][1]) or not esNumber(p[3][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_term_tmf(p): 'term : term arit_oper_2 factor' p[0] = [ p[1][0] + p[2][0] + toStrIfInt(p[3][0]), tipoNumber(p[1][1], p[3][1]) ] if p[2][0] == '/' and p[3][0] == 0: pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))
def p_term_v2mf(p): 'term : var_oper arit_oper_2 factor' p[0] = [ p[1][0] + p[2][0] + toStrIfInt(p[3][0]), tipoNumber(p[1][1], p[3][1]) ] if not esNumber(p[1][1]): pass raise SemanticException('ERRORTIPO', p.lineno(1), p.lexpos(1))