def defined_names(code, free_format=False):
root_node = Name(Name.Type.Root, <NUM_LIT:0>, <NUM_LIT:0>, '<STR_LIT:root>')<EOL>variables = []<EOL>paragraphs = []<EOL>lines = code.splitlines()<EOL>last_div_node = None<EOL>last_section_node = None<EOL>last_vars = {}<EOL>last_par = None<EOL>for i, line in enumerate(lines):<EOL><INDENT>if not free_format:<EOL><INDENT>if len(line) >= <NUM_LIT:6>:<EOL><INDENT>line = <NUM_LIT:6> * "<STR_LIT:U+0020>" + line[<NUM_LIT:6>:]<EOL><DEDENT><DEDENT>column = len(line) - len(line.lstrip())<EOL>if not line.isspace() and not line.strip().startswith("<STR_LIT:*>"):<EOL><INDENT>line = line.strip()<EOL>if regex.DIVISION.indexIn(line.upper()) != -<NUM_LIT:1> and '<STR_LIT>' not in line.upper():<EOL><INDENT>if last_div_node is not None:<EOL><INDENT>last_div_node.end_line = i<EOL><DEDENT>last_div_node, last_section_node = parse_division(<EOL>i, column, line, root_node, last_section_node)<EOL><DEDENT>elif regex.SECTION.indexIn(line.upper()) != -<NUM_LIT:1> and '<STR_LIT>' not in line.upper():<EOL><INDENT>if last_section_node:<EOL><INDENT>last_section_node.end_line = i<EOL><DEDENT>if last_div_node is None:<EOL><INDENT>name = '<STR_LIT>'<EOL>for to_check in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if to_check in line.upper():<EOL><INDENT>name = '<STR_LIT>'<EOL><DEDENT><DEDENT>last_div_node = Name(Name.Type.Division, -<NUM_LIT:1>, -<NUM_LIT:1>, name, name)<EOL>root_node.add_child(last_div_node)<EOL><DEDENT>last_section_node = parse_section(<EOL>i, column, last_div_node, last_vars, line)<EOL><DEDENT>elif (last_div_node is not None and<EOL>"<STR_LIT>" in last_div_node.name.upper()):<EOL><INDENT>tokens = line.upper().split("<STR_LIT:U+0020>")<EOL>if len(tokens) == <NUM_LIT:1> and not tokens[<NUM_LIT:0>] in ALL_KEYWORDS:<EOL><INDENT>p = parse_paragraph(<EOL>i, column, last_div_node, last_section_node, line)<EOL>if p:<EOL><INDENT>paragraphs.append(p)<EOL>if last_par:<EOL><INDENT>last_par.end_line = i<EOL><DEDENT>last_par = p<EOL><DEDENT><DEDENT><DEDENT>elif regex.VAR_PATTERN.indexIn(line.upper()) != -<NUM_LIT:1> or line.upper().lstrip().startswith('<STR_LIT>'):<EOL><INDENT>if last_div_node is None:<EOL><INDENT>last_div_node = Name(Name.Type.Division, -<NUM_LIT:1>, -<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>')<EOL>root_node.add_child(last_div_node)<EOL><DEDENT>if last_section_node is None:<EOL><INDENT>last_section_node = Name(Name.Type.Section, -<NUM_LIT:1>, -<NUM_LIT:1>, '<STR_LIT>', '<STR_LIT>')<EOL>last_div_node.add_child(last_section_node)<EOL><DEDENT>v = parse_pic_field(<EOL>i, column, last_section_node, last_vars, line)<EOL>if v:<EOL><INDENT>variables.append(v)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if last_par:<EOL><INDENT>last_par.end_line = len(lines) - <NUM_LIT:1><EOL><DEDENT>if last_div_node:<EOL><INDENT>last_div_node.end_line = len(lines)<EOL><DEDENT>if root_node and last_div_node:<EOL><INDENT>root_node.end_line = last_div_node.end_line<EOL><DEDENT>return root_node, variables, paragraphs<EOL>
Parses a cobol document and build a name tree.

For convenience, it also returns the list of variables (PIC) and
procedures (paragraphs).

:param code: cobol code to parse. Default is None.
:param free_format: True if the source code must be considered as coded
    in free format.

:return: A tuple made up of the name tree root node, the list of variables
    and  the list of paragraphs.
:rtype: Name, list of Name, list of Name