Esempio n. 1
0
def main(args):
    if not len(args):
        print >> sys.stderr, "ERROR: Must provide the analyzer with a filename!"
        sys.exit(1)

    debug = False
    prettify = False
    print_symbol_table = False
    for arg in args[:]:
        if arg == "-d":
            debug = True
        elif arg == "-p":
            prettify = True
        elif arg == "-s":
            print_symbol_table = True
        if arg.startswith("-"):
            args.remove(arg)

    filename = args[0]
    ast, symtab = analyze_file(filename, debug=debug)

    if prettify:
        print nodes.prettify(ast)
    else:
        print str(ast)

    if print_symbol_table:
        print
        print
        print "***** SYMBOL TABLE *****"
        print symtab
Esempio n. 2
0
def main(args):
    'Parse a file containing Gramola code and print the result.'
    if not len(args):
        print >> sys.stderr, 'ERROR: Must provide the parser with a filename!'
        sys.exit(1)

    debug = False
    prettify = False
    print_symbol_table = False
    for arg in args[:]:
        if arg == '-d':
            debug = True
        elif arg == '-p':
            prettify = True
        elif arg == '-s':
            print_symbol_table = True
        if arg.startswith('-'):
            args.remove(arg)

    filename = args[0]
    p = Parser()
    ast = p.parse_file(filename, debug=debug)

    if prettify:
        print nodes.prettify(ast)
    else:
        print str(ast)

    if print_symbol_table:
        print p.symbol_table