def main():
    print "############# Starting run of Compyler #############"
    if len(sys.argv) > 1:
        fname = sys.argv[1]
        sourceText = open(str(fname)).read()
        parser.parse(sourceText)
        print "############# Completed run of Compiler #############"
    else:
        print "User Input Error: This program requires a filepath parameter..."
Exemple #2
0
def compileString(text):
    ast = parser.parse(text)
    analysis = ModuleSemanticAnalysis()
    analysis.performOn(ast)
    if analysis.errorCount > 0:
        return None
    return analysis.module
Exemple #3
0
def main():
    '''
    B{The main function of the application} U{http://code.google.com/p/pdftoref/}
    Here is done first the parsing of the command line to get if parse a pdf file
    or a set of pdf files in a directory. When the parsing of the pdf is done and 
    the exctractor finishe, it writes the result into an html file. 
    '''
   
    (content,flag,urlFlag,bibtexFlag,downloadPdfFlag) =  parser.parse(sys.argv)
    if flag == 'None':
        parser.usage()
        sys.exit(2)
        
    elif flag == 'file':
        print("PdftoRef> Running on the file: "+ content)
        do(content,urlFlag,bibtexFlag,downloadPdfFlag)

         
    elif flag == 'dir':
        print("PdftoRef> Running on the directory: "+ content)
        
        '''Check if the dir under linux finish for \\'''
        if content[len(content)-1:]<> "/":
                       content+="/"

        '''Getting the pdf files in the dir'''
        pdfFiles = parser.listPdfFiles(content)
        lenght = len(pdfFiles)
        
        '''Itering over the files and extract the info one by one'''
        for each in pdfFiles:
            print("PdftoRef> Extracting data from file: "+ each)
            do(content+each,urlFlag,bibtexFlag,downloadPdfFlag)
Exemple #4
0
def compileString(text):
    ast = parser.parse(text)
    analysis = ModuleSemanticAnalysis()
    analysis.performOn(ast)
    if analysis.errorCount > 0:
        return None
    return analysis.module
Exemple #5
0
def run(document):
    tokens = lexer.run(document)
    tokens = cut_of_eos(tokens)
    tokens = remove_repeated_eos(tokens)
    tokens.append(Token("\n", "", tokens[-1].line))

    parse_tree = None

    try:
        parse_tree = parser.parse(tokens)
    except InternalError as e:
        print(bcolors.HEADER + "There is a syntax error in your script!" +
              bcolors.ENDC)
        print(str(e.args[0]))

        if DETAILED_ERROR:
            print("\n\n-------Detailed Parse Tree-------")
            try:
                print(e.args[1])
            except:
                pass
        sys.exit(1)

    ast = None
    try:
        ast = abstract_syntax_tree.generate(parse_tree, None)
    except InternalError as e:
        print(
            bcolors.HEADER +
            "There is a parse tree sequence without a corresponding AST rule, this most likely "
            "isn't an error with your script but with the interpreter." +
            bcolors.ENDC)
        try:
            body = ""
            for t in e.args[1].body:
                body += t.__repr__() + " "

            print(e.args[1].head + " -> " + body)
        except:
            pass
        sys.exit(1)

    state = State()

    try:
        ast.generate(state)
    except InternalError as e:
        msg = bcolors.FAIL + str(e.args[0]) + bcolors.ENDC
        print(bcolors.HEADER +
              "An error occurred while executing your script!" + bcolors.ENDC)
        print(msg)

        if DETAILED_ERROR:
            print("\n\n-------Detailed Abstract Syntax Tree-------")
            try:
                print(ast)
            except:
                pass

        sys.exit(1)
Exemple #6
0
from Interp import LOLCodeInterpreter
from Parser import parser
import argparse

if __name__ == "__main__":
    arg_parser = argparse.ArgumentParser(description='LolCode interpretator')
    arg_parser.add_argument('-f', nargs=1, help='input filename')
    args = arg_parser.parse_args()
    filename = args.f[0]
    with open(filename, 'r') as f:
        data = f.read()
        if data:
            try:
                tree = parser.parse(data)
                interpret = LOLCodeInterpreter(tree)
                interpret.execute_program()
            except Exception as e:
                print(e)
Exemple #7
0
args = arg_parser.parse_args()
start = time.clock()

if args.input:
    test_file = args.input

if args.output:
    out_file = args.output

with open(test_file, 'r') as infile:
    data = infile.read()
print("=" * 20)
SemanticLogger.info(None, 'compiling {}'.format(path.basename(test_file)))

parse_tree_root = parser.parse(data,
                               lexer=lex.lex(module=Lexer, debug=0),
                               debug=log)

if args.visualize:
    if not path.exists(args.visualize):
        os.makedirs(args.visualize)
    graph(parse_tree_root, path.join(args.visualize, 'original_ast'))

if parse_tree_root:
    static_semantic_analyzer = SemanticAnalyzer(parse_tree_root)
    static_semantic_analyzer.analyze()
    if args.visualize:
        static_semantic_analyzer.symbol_table.to_graph(
            path.join(args.visualize, 'symb_tab.png'))
    SemanticLogger.info(
        None, "Find {} warnings and {} errors".format(SemanticLogger.n_warn,