git @ Cat's Eye Technologies Dieter / master src /

Tree @master (Download .tar.gz) @masterraw · history · blame

#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" -- driver for parsing/typechecking the Dieter programming language.
$Id: 382 2010-01-28 23:40:43Z cpressey $

import sys
from optparse import OptionParser
import logging

from dieter.scanner import Scanner
from dieter.parser import Parser
from dieter.context import TypingContext

def load(filename, options):
    with open(filename, "rb") as f:
        scanner = Scanner(
    parser = Parser(scanner)
    ast = parser.Dieter()
    context = TypingContext(None)
    if options.verbose:
    if options.dump_ast:
        print("--- AST: ---")
    if options.dump_symtab:
        print("--- Symbol Table: ---")

def main(argv):
    optparser = OptionParser("[python] {options} {source.dtr}\n" + __doc__)
    optparser.add_option("-a", "--dump-ast",
                         action="store_true", dest="dump_ast", default=False,
                         help="dump AST after source is parsed")
    optparser.add_option("-s", "--dump-symtab",
                         action="store_true", dest="dump_symtab", default=False,
                         help="dump symbol table after source is parsed")
    optparser.add_option("-v", "--verbose",
                         action="store_true", dest="verbose", default=False,
                         help="""be verbose about actions taken internally
                                 (e.g. type unification)""")
    (options, args) = optparser.parse_args(argv[1:])
    for filename in args:
        load(filename, options)

if __name__ == "__main__":