예제 #1
0
def parse_integer_literal(queue):

    if len(queue) == 0:
        print("ERROR: Expected an integer")
        raise SystemExit
    
    token = queue.pop(0)

    if not LexicalAnalyzer.is_integer_literal(token[1]):
        print("ERROR: Not an integer at line", token[0])
        raise SystemExit
    
    return token[1]
예제 #2
0
def parse_expression(queue):
    if len(queue) == 0:
        print("ERROR: Code Not Complete: Expected an expression")
        raise SystemExit
    
    else:
        value = queue[0][1]

        if LexicalAnalyzer.is_integer_literal(value):
            queue.pop(0)
            e_rec = parse_expression_recursion_fix(queue)

            e1 = Expression1(value, e_rec)
            return e1

        elif value == "true":
            queue.pop(0)
            e_rec = parse_expression_recursion_fix(queue)

            e2 = Expression2(e_rec)
            return e2

        elif value == "false":
            queue.pop(0)
            e_rec = parse_expression_recursion_fix(queue)

            e3 = Expression3(e_rec)
            return e3

        elif value == "this":
            queue.pop(0)
            e_rec = parse_expression_recursion_fix(queue)

            e5 = Expression5(e_rec)
            return e5

        elif value == "new":
            queue.pop(0)
            n = parse_new_object(queue)
            e_rec = parse_expression_recursion_fix(queue)

            e6 = Expression6(n, e_rec)
            return e6

        elif value == "!":
            queue.pop(0)
            exp = parse_expression(queue)
            throw_exception_expression(exp)

            e_rec = parse_expression_recursion_fix(queue)

            e7 = Expression7(exp, e_rec)
            return e7

        elif value == "(":
            queue.pop(0)

            exp = parse_expression(queue)
            throw_exception_expression(exp)

            validate(queue, ")")

            e_rec = parse_expression_recursion_fix(queue)

            e8 = Expression8(exp, e_rec)
            return e8

        elif LexicalAnalyzer.is_id(value):
            i = parse_identifier(queue)
            e_rec = parse_expression_recursion_fix(queue)

            e4 = Expression4(i, e_rec)
            return e4

        else:
            e = Epsilon()
            return e