Beispiel #1
0
def run(args):
    fileContent = ''
    with open(args.file, 'r') as fd:
        fileContent = fd.read()

    if args.lex:
        return '\n'.join(map(str, runLex(fileContent)))
    elif args.yacc:
        return runYacc(fileContent, debug=args.dbg)
    else:
        # give final compiled result in interactive
        return runYacc(fileContent, debug=args.dbg)
Beispiel #2
0
def test_identicalCode():
    folderPath = PurePath(os.path.dirname(__file__), 'identicalCode')
    asm = getContent(PurePath(folderPath, '1-vanilla.code'))
    files = list(
        filter(lambda file: file.split('.')[-1] == 'code',
               os.listdir(folderPath)))
    files.sort()
    for file in files:
        filePath = PurePath(folderPath, file)
        assert runYacc(getContent(filePath), clearContext=True) == asm
Beispiel #3
0
def assertCompilationException(code, exceptionSubStr):
    with pytest.raises(CompilationException) as e:
        runYacc(code, clearContext=True)
    assert exceptionSubStr in str(e.value)
Beispiel #4
0
def identical(instr):
    return runYacc(instr) == instr + '\n'
Beispiel #5
0
def checkCodeToASM(file):
    try:
        assert runYacc(file.code, clearContext=True) == file.asm
    except:  # noqa
        print('\nfail runYacc on file: {}\n'.format(file.file))
        raise SystemError()