예제 #1
0
파일: checkSMC.py 프로젝트: Lamparu/TAlab1
def checkSMCstr(strch, dict_valnames):
    machine = AppClass.AppClass()
    # print(machine.GetValDict())
    machine.SetValDict(dict_valnames)
    # print(machine.GetValDict())
    match = machine.CheckString(strch)
    # print(machine.GetValDict())
    if match:
        return str(machine.GetStrNum()) + ' : ' + str(machine.getNumLitstr())
    else:
        return 'Unacceptable'
예제 #2
0
def from_console():  # Ctrl + D to stop
    start = time.time()
    recognizer = AppClass.AppClass()
    for line in sys.stdin:
        match = recognizer.CheckString(line[:-1])
        if match:
            print('OK')
            check = recognizer.check_conflicts()
            if check is not None:
                print('conflict: ' + check[0] + ' initial type is ' + check[1])

        else:
            print('NOT OK')
    end = time.time()
    with open('time.txt', 'w') as f:
        f.write(str(end - start))
예제 #3
0
def iscorrect(st):
    retcode = 0
    if len(st) < 1:
        print("No string to check.\n")
        retcode = 2
    else:
        appobject = AppClass.AppClass()
        if appobject.CheckString(st) == False:
            f.write(st + ' is not acceptable\n')
            retcode = 1
        else:
            if d.get(appobject._func) == None:
                d[appobject._func] = 1
            else:
                d[appobject._func] = d[appobject._func] + 1
            f.write(st + ' is acceptable\n')
    return retcode
예제 #4
0
def from_file():
    recognizer = AppClass.AppClass()
    f = open('generated_10000.txt', 'r')
    res = open('results.txt', 'w')
    start = time.time()
    for line in f.readlines():
        match = recognizer.CheckString(line)
        if match:
            res.write(line + ' OK ')
            check = recognizer.check_conflicts()
            if check is not None:
                res.write('conflict: ' + check[0] + ' initial type is ' +
                          check[1] + '\n')
            else:
                res.write('\n')
        else:
            res.write(line + ' NOT OK ' + '\n')
    end = time.time()
    with open('time.txt', 'w') as tm:
        tm.write(str(end - start))
    f.close()
예제 #5
0
파일: checkSMC.py 프로젝트: Lamparu/TAlab1
def SMCcheck():
    machine = AppClass.AppClass()
    f = open('genSTR.txt', 'r')
    res = open('resSMC.txt', 'w')
    ftime = open('timeSMC.txt', 'w')
    time_start = time.perf_counter()
    numline = 0
    for line in f.readlines():
        numline += 1
        match = machine.CheckString(line)
        if match:
            # print(machine.GetStrNum() + ': ' + str(machine.getNumLitstr()))
            res.write(
                str(machine.GetStrNum()) + ' : ' +
                str(machine.getNumLitstr()) + '\n')
        if numline % 10000 == 0:
            ftime.write(str(time.perf_counter() - time_start) + '\n')
    print('***File was checked by SMC***')
    ftime.close()
    f.close()
    res.close()
예제 #6
0
def analyze(filename):
    checker = AppClass.AppClass()
    with open('timing-smc.txt', 'w') as out:
        out.write('# amount TIME\n')
    with open(filename, 'r') as dt:
        cnt = 0
        start = time.time()
        for line in dt:
            cnt += 1
            checker.CheckString(line)
            if not cnt % 100000:
                end = time.time()
                with open('timing-smc.txt', 'a') as out:
                    out.write(
                        str(cnt / 100000) + ' ' + str(end - start) + '\n')

    cnt = checker.get_lines_read()
    dct = dict(reversed(sorted(checker.get_dict().items(),
                               key=lambda x: x[1])))

    with open('answer_smc.txt', 'w') as ans:
        ans.write('Lines read successfully: ' + str(cnt) + '\n')
        ans.writelines(
            ['Variable ' + x + '---' + str(dct[x]) + '\n' for x in dct.keys()])
예제 #7
0
# $Id: checkstring.py,v 1.1 2005/05/28 17:48:29 cwrapp Exp $
#
# CHANGE LOG
# $Log: checkstring.py,v $
# Revision 1.1  2005/05/28 17:48:29  cwrapp
# Added Python examples 1 - 4 and 7.
#
#

import sys

import AppClass

retcode = 0
if len(sys.argv) < 2:
    print "No string to check.\n"
    retcode = 2
elif len(sys.argv) > 2:
    print "Only one argument is accepted.\n"
    retcode = 3
else:
    appobject = AppClass.AppClass()
    str = sys.argv[1]
    if appobject.CheckString(str) == False:
        result = "not acceptable"
        retcode = 1
    else:
        result = "acceptable"
    print 'The string "%s" is %s.\n' % (str, result)
sys.exit(retcode)