view src/converter.py @ 16:100efeeb2ad9

remove unnecessary variable "s_local" in cTranslator.
author Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp>
date Mon, 05 Jul 2010 06:25:44 +0900
parents 11fba907c0af
children ec36e784df2e
line wrap: on
line source

#!/usr/bin/env python

import sys
from dfareg import Regexp, CallGraph
from cTranslator import CTranslator
from cbcTranslator import CbCTranslator
from optparse import OptionParser

def main(argv):
    myusage = "%prog [-C] regexp"
    psr = OptionParser(usage=myusage)
    psr.add_option("-C", action="store_true", dest="emitC", default=False, help="emit C-source")
    psr.add_option("--from-dfa", action="store_true", dest="dfa", default=True, help="translate from DFA")
    psr.add_option("--from-nfa", action="store_true", dest="nfa", default=False, help="translate from NFA")
    psr.add_option("-o", action="store", type="string", dest="output", default=False, help="output file", metavar="FILE")
    psr.add_option("-g", action="store_true", dest="debug", default=False, help="embed debug info")
    psr.add_option("-D", action="store_true", dest="emitDot", default=False, help="emit Dot file")
    (opts, args) = psr.parse_args(sys.argv)
    if len(args) == 1:
        psr.print_help()
        exit()
    reg = Regexp(args[1])
    if not opts.output:
        output = sys.stdout
    else:
        output = open(opts.output,"w")

    if opts.nfa:
        fa = reg.nfa
    else:
        fa = reg.dfa

    if opts.emitDot:
        r.emitDot()
    elif opts.emitC:
        translator = CTranslator(reg.regexp, CallGraph(fa))
        translator.debug = opts.debug
    else:
        translator = CbCTranslator(reg.regexp, CallGraph(fa))
        translator.debug = opts.debug

    translator.translate(output)

if __name__ == '__main__' : main(sys.argv)