import argparse
import os
import shutil
import subprocess
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--output', help='output path of yacc')
parser.add_argument('--bisoninput', help='input path of bison')
parser.add_argument('--flexinput', help='input path of flex')
options = parser.parse_args()
yacc_path = options.output
parser_file = os.path.join(yacc_path, "parser.cpp")
lexer_file = os.path.join(yacc_path, "lexer.cpp")
flexlexer_file = os.path.join(yacc_path, "FlexLexer.h")
if not os.path.exists(yacc_path):
os.makedirs(yacc_path)
bison_cmd = ['bison', '-o', parser_file, options.bisoninput]
parse_scripts = subprocess.check_call(bison_cmd)
flex_cmd = ['flex', '-+', '-o', lexer_file, options.flexinput]
parse_scripts = subprocess.check_call(flex_cmd)
shutil.copy2("/usr/include/FlexLexer.h", flexlexer_file)