def p_ainit(p): 'ainit : NAME EQUAL funexp' t1, e = p[3] t2 = type[p[1]] if t1 == t2: pmc.set_init_value(rea(p[1], dic), rea(e, dic)) else: raise Exception("bad type in init :" + e + " = " + p[1])
def p_declParamMultiple(p): 'declParam : PARAM type NAME LACCO funexp POINTPOINT funexp RACCO' global paramnameglob paramnameglob = p[3] dic[p[3]] = my_func t1, e1 = p[5] t2, e2 = p[7] for i in range(rea(e1, dic), rea(e2, dic) + 1): pmc.add_parameter(Symbol(p[3] + str(i)))
def p_updatesProb(p): '''updatesProb : funexp DDOT updates PLUS updatesProb | funexp DDOT updates | updates''' if len(p) > 4: _, e = p[1] p[0] = p[5] + [[rea(e, dic), p[3]]] elif len(p) > 3: _, e = p[1] p[0] = [[rea(e, dic), p[3]]] else: p[0] = [[1, p[1]]]
def p_trans(p): '''trans : LCROCHET RCROCHET funexp FLECHE updatesProb | LCROCHET NAME RCROCHET funexp FLECHE updatesProb''' if len(p) == 6: t, e = p[3] if t == "bool": curentMod.add_transition("", rea(e, dic), p[5]) else: raise Exception('Not bool in cond' + e) else: t, e = p[4] if t == "bool": curentMod.add_transition(p[2], rea(e, dic), p[6]) else: raise Exception('Not bool in cond' + e)
def p_listIdState(p): '''listIdState : NAME EQUAL NAME | NAME EQUAL NAME VIRGULE listIdState''' dic[p[3]] = rea(p[3], dic) type[p[3]] = type[p[1]] try: curentMod.replace(dic[p[1]], dic[p[3]]) except: curentMod.replace(p[1], p[3])
def p_declConstl(p): 'declConst : CONST type NAME EQUAL funexp' t, e = p[5] if t == p[2]: dic[p[3]] = rea(e, dic) type[p[3]] = p[2] else: raise Exception("invalid type cons decl : " + p[3] + " " + t + " " + p[2])
def p_rew(p): '''rew : QUOTE NAME QUOTE funexp DDOT funexp SC rew | LCROCHET NAME RCROCHET funexp DDOT funexp SC rew | LCROCHET RCROCHET funexp DDOT funexp SC rew | empty''' if p[1] == "[": if len(p) == 9: t, e = p[4] _, er = p[6] if t == 'bool': pmc.add_reward(p[2], rea(e, dic), rea(er, dic)) else: raise Exception("Invalid type in condition of reward " + p[2]) else: t, e = p[3] _, er = p[5] if t == 'bool': pmc.add_reward('', rea(e, dic), rea(er, dic)) else: raise Exception("Invalid type in condition of reward " + p[2])
def p_globall(p): '''declGlobal : GLOBALL NAME DDOT LCROCHET funexp POINTPOINT funexp RCROCHET | GLOBALL NAME DDOT LCROCHET funexp POINTPOINT funexp RCROCHET INIT funexp | GLOBALL NAME DDOT BOOL''' dic[p[2]] = rea(p[2], dic) if len(p) > 10: type[p[2]] = "int" t1, e1 = p[5] t2, e2 = p[7] pmc.add_global_variable(dic[p[2]], rea(e1, dic), rea(e2, dic)) elif len(p) > 6: t1, e1 = p[5] t2, e2 = p[7] t3, e3 = p[10] type[p[2]] = "int" pmc.add_global_variable(dic[p[2]], rea(e1, dic), rea(e2, dic), rea(e3, dic)) else: type[p[2]] = "bool" pmc.add_global_variable(dic[p[2]], rea("true", dic), rea("false", dic))
def p_statedecl(p): '''stateDecl : NAME DDOT LCROCHET funexp POINTPOINT funexp RCROCHET | NAME DDOT LCROCHET funexp POINTPOINT funexp RCROCHET INIT funexp | NAME DDOT BOOL''' dic[p[1]] = rea(p[1], dic) if len(p) > 8: _, e1 = p[4] _, e2 = p[5] _, e3 = p[9] curentMod.add_state(dic[p[1]], rea(e1, dic), rea(e2, dic), rea(e3, dic)) type[p[1]] = "int" elif len(p) > 5: type[p[1]] = "int" _, e1 = p[4] _, e2 = p[6] curentMod.add_state(dic[p[1]], rea(e1, dic), rea(e2, dic)) else: type[p[1]] = "bool" curentMod.add_state(dic[p[1]], True, False)
def p_upd(p): 'upd : LPAR NAME NEW EQUAL funexp RPAR' _, e = p[5] p[0] = {rea(p[2], dic): rea(e, dic)}
def p_declParaml(p): '''declParam : PARAM type NAME DDOT LCROCHET funexp POINTPOINT funexp RCROCHET | PARAM type NAME''' dic[p[3]] = rea(p[3], dic) type[p[3]] = "int" pmc.add_parameter(dic[p[3]])
def p_formula(p): 'formula : FORMULA NAME EQUAL funexp' t, e = p[4] dic[p[2]] = rea(e, dic)