def p_return_expr(p):
    """ statement : RETURN expr
    """
    if not FUNCTION_LEVEL:  # At less one level
        syntax_error(p.lineno(1), 'Syntax Error: Returning value out of FUNCTION')
        p[0] = None
        return

    if FUNCTION_LEVEL[-1].kind is None:  # This function was not correctly declared.
        p[0] = None
        return

    if FUNCTION_LEVEL[-1].kind != KIND.function:
        syntax_error(p.lineno(1), 'Syntax Error: SUBs cannot return a value')
        p[0] = None
        return

    if is_numeric(p[2]) and FUNCTION_LEVEL[-1].type_ == TYPE.string:
        syntax_error(p.lineno(2), 'Type Error: Function must return a string, not a numeric value')
        p[0] = None
        return

    if not is_numeric(p[2]) and FUNCTION_LEVEL[-1].type_ != TYPE.string:
        syntax_error(p.lineno(2), 'Type Error: Function must return a numeric value, not a string')
        p[0] = None
        return

    p[0] = make_sentence('RETURN', FUNCTION_LEVEL[-1],
                         make_typecast(FUNCTION_LEVEL[-1].type_, p[2],
                                       p.lineno(1)))
def p_return_expr ( p ) : if not FUNCTION_LEVEL : syntax_error ( p . lineno ( 1 ) , 'Syntax Error: Returning value out of FUNCTION' ) p [ 0 ] = None return if FUNCTION_LEVEL [ - 1 ] . kind is None : p [ 0 ] = None return if FUNCTION_LEVEL [ - 1 ] . kind != KIND . function : syntax_error ( p . lineno ( 1 ) , 'Syntax Error: SUBs cannot return a value' ) p [ 0 ] = None return if is_numeric ( p [ 2 ] ) and FUNCTION_LEVEL [ - 1 ] . type_ == TYPE . string : syntax_error ( p . lineno ( 2 ) , 'Type Error: Function must return a string, not a numeric value' ) p [ 0 ] = None return if not is_numeric ( p [ 2 ] ) and FUNCTION_LEVEL [ - 1 ] . type_ != TYPE . string : syntax_error ( p . lineno ( 2 ) , 'Type Error: Function must return a numeric value, not a string' ) p [ 0 ] = None return p [ 0 ] = make_sentence ( 'RETURN' , FUNCTION_LEVEL [ - 1 ] , make_typecast ( FUNCTION_LEVEL [ - 1 ] . type_ , p [ 2 ] , p . lineno ( 1 ) ) )
statement : RETURN expr