def main(): print '*** Parabench Module Preprocessor', VERSION, '***' #callPath = os.path.dirname(inspect.getfile(sys._getframe()))+'/' for module_file in glob.glob('modules/*.c'): module = Module(module_file) if VERBOSE: module.print_parameters() for source_file in hooks: cg = CodeGenerator(source_file) for hook in hooks[source_file]: print 'ppc: %s -> %s -> %s' % (module_file, source_file, hook) if generator[hook]: g = generator[hook]() template = Template(hook) g.generate(template, module) else: print 'No generator given for hook "%s"' % hook cg.write() # Copy production source files to gen dir: genfiles = hooks.keys() srcfiles = set(glob.glob('*.c') + glob.glob('*.h') + glob.glob('*.l') + glob.glob('*.y')) for g in genfiles: if g in srcfiles: srcfiles.remove(g) source = ' '.join(srcfiles) if source != '': os.system('cp %s gen/' % source) if VERBOSE: print '\n\nGenerated Code:' cg.print_code()
factory = AstFactory(output) parser = Parser(token_array, output, factory) #print 'parse start' parser.parse() print 'parse success' if parser.get_error_message() != '': print parser.get_error_message() exit() symbol_table = factory.get_symbol_table() ast_root = factory.get_ast_root() #print 'code generation start' if symbol_table: code_generation = CodeGenerator(symbol_table, ast_root) code_generation.generate_code() code_generation.print_code() else: #if the option is -s, it will run the scanner and produce a list of tokens if sys.argv[1] == '-s': input_string = ''; #if the second argument exist, it means read from file if len(sys.argv) == 3: #Read the file if os.path.exists(sys.argv[2]): f = open(sys.argv[2]) input_string = f.read() #if the directory of the file does not exist else: print 'error: The directory of the file does not exist' #if the second argument does not exist, it will read from standard input