示例#1
0
def checkForNumbers(string):
    i = 0
    while i < len(string):
        if string[i].isdigit():
            raise_parsing_error(f"Error: bad char in line: {string}")

        i += 1
示例#2
0
def parse_file(file_path, tab):
    check(file_path, tab)
    if not tab:
        raise_parsing_error("Error: Empty file")
    for id, e in enumerate(tab):
        tab[id] = translate(e)
    parse_tab(tab)
示例#3
0
def doubleLetter(tab):  # Check for two letters consecutively
    for line in tab:
        checkForNumbers(line)
        for i in range(1, len(line)):
            if line[i - 1].isalpha() and line[i].isalpha():
                if line[0] != "=" and line[0] != "?" and line[0] != "(":
                    raise_parsing_error(
                        f"Error: two consecutive facts in line: {line}")
示例#4
0
def validParenthesis(tab):
    for line in tab:
        if '(' in line or ')' in line:
            countop = line.count('(')
            countclose = line.count(')')
            if countop - countclose != 0:
                raise_parsing_error(f"Error: Missing parenthesis : {line}")
            if matchingParenthesis(line) == False:
                raise_parsing_error("Error: Bad parenthesis")
示例#5
0
def is_rule(input):
    op = "=>"
    if "<=>" in input:
        op = "<=>"
    splitted = input.split(op)
    without_empty = list(filter(None, splitted))
    if len(without_empty) != 2:
        raise_parsing_error("Operator should have data on both side.")
    return True
示例#6
0
def check(file_path, tab):
    input_file = 0
    if os.path.isfile(file_path):
        try:
            input_file = open(file_path, "r")
        except IOError as e:
            raise_parsing_error(f"Error: File can't by open : {e}")
        for line in input_file:
            remove_empty_and_comments(tab, line)
    else:
        raise_parsing_error("Error: File doesn't exist")
示例#7
0
def min_step(tab):  # Check if there are a minimum steps to be resolv
    #	Flag to know if steps are pass
    flag = 0
    #	Array to errors list
    err = ["Error: Missing ", " expression", "X => Y", "=XXX", "?XXX"]

    for line in tab:
        for operator in operand_n:
            if not flag and operator in line:
                flag |= 1
        if line == "=" or (line[0] in ['?', '='] and line[1].isalpha()):
            flag |= (4 if line[0] == '?' else 2)
    if not ((flag & 1) and (flag & 2) and (flag & 4)):
        if not (flag & 1):
            raise_parsing_error(err[0] + err[2] + err[1])
        if not (flag & 2):
            raise_parsing_error(err[0] + err[3] + err[1])
        if not (flag & 4):
            raise_parsing_error(err[0] + err[4] + err[1])