def parse_exp_only_one(queue): exp = parse_expression(queue) if type(exp) == Epsilon: e = Epsilon() return e else: e_one = ExpOnlyOne(exp) return e_one
def parse_exp(queue): ex = parse_expression(queue) if type(ex) == Epsilon: e = Epsilon() return e else: exp = parse_exp(queue) final_exp = Exp(ex, exp) return final_exp
def parse_md(queue): m = parse_method_declaration(queue) if type(m) == Epsilon: e = Epsilon() return e else: md = parse_md(queue) final_md = MD(m, md) return final_md
def parse_st(queue): s = parse_statement(queue) if type(s) == Epsilon: e = Epsilon() return e else: st = parse_st(queue) final_st = ST(s, st) return final_st
def parse_vd(queue): v = parse_variable_declaration(queue) if type(v) == Epsilon: e = Epsilon() return e else: vd = parse_vd(queue) final_vd = VD(v, vd) return final_vd
def parse_cd(queue): c = parse_class_declaration(queue) if type(c) == Epsilon: cd = Epsilon() return cd else: cd = parse_cd(queue) final_cd = CD(c, cd) return final_cd
def parse_expression_recursion_fix(queue): o = parse_operations(queue) if type(o) == Epsilon: e = Epsilon() return e else: e_rec = parse_expression_recursion_fix(queue) final_e_rec = ExpressionRecursionFix(o, e_rec) return final_e_rec
def parse_parameters(queue): ty = parse_type(queue) if type(ty) == Epsilon: e = Epsilon() return e i = parse_identifier(queue) pl = parse_parameters_list(queue) p = Parameters(ty, i, pl) return p
def parse_method_declaration(queue): if len(queue) == 0: print("ERROR: Code not complete") raise SystemExit else: value = queue[0][1] if value == Modifier.PRIVATE: mod = Modifier.PRIVATE queue.pop(0) elif value == Modifier.PUBLIC: mod = Modifier.PUBLIC queue.pop(0) else: e = Epsilon() return e ty = parse_type(queue) if type(ty) == Epsilon: print("ERROR: Expected a data type found: \"" + queue[0][1] + "\" at line", queue[0][0]) raise SystemExit i = parse_identifier(queue) validate(queue, "(") p = parse_parameters(queue) validate(queue, ")") validate(queue, "{") vd = parse_vd(queue) st = parse_st(queue) validate(queue, "return") exp = parse_expression(queue) throw_exception_expression(exp) validate(queue, ";") validate(queue, "}") m = MethodDeclaration(mod, ty, i, p, vd, st, exp) return m
def parse_variable_declaration(queue): ty = parse_type(queue) if type(ty) == Epsilon: e = Epsilon() return e else: i = parse_identifier(queue) validate(queue, ";") v = VarDeclaration(ty, i) return v
def parse_parameters_list(queue): if len(queue) == 0: print("ERROR: Code not complete. Expected: )") raise SystemExit value = queue[0][1] if value != ",": e = Epsilon() return e queue.pop(0) ty = parse_type(queue) if type(ty) == Epsilon: print("ERROR: Expected a data type") raise SystemExit i = parse_identifier(queue) pl = parse_parameters_list(queue) final_pl = ParametersList(ty, i, pl) return final_pl
def throw_exception_expression(expression): if type(expression) == Epsilon: print("ERROR: Expected an expression") raise SystemExit