def process_converter(filename, form_xml, debug, cl_path):
    if not filename:
        return None

    if form_xml:
        form = form_xml.xpath('/CALC/FORMSET/FORM/@val')[0].upper()

    preprocessed = preprocess_calc_file(filename, debug=debug, cl_path=cl_path)

    input_stream = InputStream(preprocessed)
    tree = antrl_parse(input_stream, debug)
    xml = tree2xml(tree)
    if debug:
        print "##### parse converter: %s #####" % filename
        pretty_print(xml)
    withforms = xml.xpath('//WithForms[ID[1][@val="%s"]]' % form)
    if not withforms:
        return

    withforms = withforms[0]
    fedform = withforms.xpath("ID[2]/@val")[0].upper()
    for each in withforms.xpath(".//Assign"):
        each.set('fed', '1')
        id = each.getchildren()[0]
        id.set('val', "%s.%s" % (form, id.get('val').upper()))

        for id in each.getchildren()[1].xpath('.//ID'):
            id.set('val', "%s.%s" % (fedform, id.get('val').upper()))
            id.set('fed','1')


    #Cleanup boolean\literal assigns
    for each in withforms.xpath(".//IfStruct/Assign[Boolean|Literal]"):
        each.getparent().remove(each)

    if debug:
        print "##### withforms #####"
        pretty_print(withforms)

    form_xml.append(withforms)

    with open(arg.pref_file) as settings_file:
        settings = json.load(settings_file)

    if arg.use_preparsed:
        root = etree.parse("output/preparsed.xml")
    else:
        with open(settings.get("preprocessed")) as f:
            preprocessed = f.read()

        input_stream = InputStream(preprocessed)

        tree = antrl_parse(input_stream, debug)

        root = tree2xml(tree, debug)


        for each in root.xpath('//CONCAT'):
            each.set('val', "__".join(each.xpath("ArgList/*[2]/@val")))
            each.tag = 'String'
            each.remove(each.getchildren()[0])

        with open('output/preparsed.xml', 'w') as f:
            f.write(etree.tostring(root, pretty_print = True))

    if debug:
        print "##ParseTreeWalker##"
        pretty_print(root)

    ptformset_xml = etree.parse(settings['ptformset_xml_path'])
    print "\n....Loading preferences from: %s" %  arg.pref_file
    with open(arg.pref_file) as settings_file:
        settings = json.load(settings_file)
    print "\n\n....Settings:"
    print json.dumps(settings,indent=4)
    print "\n\n"

    preprocessed = preprocess_calc_file(settings['calc_filename'], debug=debug, cl_path=settings['cl_path'])

    print "\n\n\n"

    input_stream = InputStream(preprocessed)

    tree = antrl_parse(input_stream, debug)

    root = tree2xml(tree)

    if debug:
        print "##ParseTreeWalker##"
        pretty_print(root)

    process_converter(settings['cvt_filename'], form_xml=root, debug=debug, cl_path=settings['cl_path'])

    resolve_vars(root, use_tke=False)

    fix_self_referencing_assigns(root)

    if debug:
        print "##ParseTreeWalker##"
        pretty_print(root)