def parse(sourceText, **kwargs):
    global lexer, verbose
    verbose = kwargs.get("verbose", False)

    lexer.initialize(sourceText)
    getToken()
    program()
    if verbose:
        print "~" * 80
        print "Successful parse!"
        print "~" * 80
    return ast
Example #2
0
def main(sourceText):
    global f
    f = open(outputFilename, "w")

    # # scanner driver
    # writeln("Here are the characters returned by the scanner:")
    # writeln("  line col  character")
    # scanner.initialize(sourceText)
    # character = scanner.get()
    # while True:
    #     writeln(character)
    #     if character.cargo == ENDMARK : break
    #     character = scanner.get()

    # # lexer driver
    writeln("Here are the tokens returned by the lexer:")
    lexer.initialize(sourceText)
    while True:
        token = lexer.get()
        writeln(token.show(True))
        print token.show(True)
        if token.type == EOF: break
    f.close()