Пример #1
0
def test_parser(program):
    from compiler.parser import Parser

    p = Parser(program)
    try:
        while True:
            p.system_goal()
            break
    except (SyntaxError, LexicalError) as e:
        print "Lexical or Syntax error occured with char: '%s'" % e.err
    else:
        for o in p.output:
            print o
Пример #2
0
    def test_system_goal(self):
        t1 = None
        with open( self.input_file, 'w') as f:
            f.write('BEGIN A := BB + 314 + A; END$')

        with open(self.input_file, 'r') as f:
            p = Parser(f)
            p.system_goal()

        with open(self.output_file, 'r') as f:
            t1 = f.read()
        os.remove(self.output_file)
        os.remove(self.input_file)

        self.assertEqual(t1, "HALT")
Пример #3
0
def test_compile(in_file, out_file):
    from compiler.parser import Parser
    p = Parser(in_file)
    try:
        output = WriteObj()
        sys.stdout = output
        p.system_goal()
    except Exception as e:
        print traceback.format_exc()
    else:
        sys.stdout = sys.__stdout__
        out_file.write(output.content)
        print "Compiled to location: %s" % out_file.name

    if p.errors:
        print "The following errors where detected and recovery was attempted"
        for err in p.errors:
            print err