def p_action_if_fmla_lcb_action_rcb(p): "action : IF fmla LCB action RCB" p[0] = IfAction(p[2], p[4]) p[0].lineno = get_lineno(p, 1)
def p_action_if_fmla_lcb_action_rcb_else_LCB_action_RCB(p): "action : IF fmla LCB action RCB ELSE action" p[0] = IfAction(p[2], p[4], p[7]) p[0].lineno = get_lineno(p, 1)
def p_action_if_somefmla_lcb_action_rcb(p): 'action : IF somefmla LCB action RCB' p[0] = IfAction(p[2], fix_if_part(p[2], p[4])) p[0].lineno = get_lineno(p, 1)
def p_action_if_somefmla_lcb_action_rcb_else_LCB_action_RCB(p): 'action : IF somefmla LCB action RCB ELSE action' p[0] = IfAction(p[2], fix_if_part(p[2], p[4]), p[7]) p[0].lineno = get_lineno(p, 1)
def p_action_if_fmla_lcb_action_rcb(p): 'action : IF fmla LCB action RCB' p[0] = IfAction(p[2], p[4]) p[0].lineno = get_lineno(p, 1)
def p_action_if_fmla_lcb_action_rcb_else_LCB_action_RCB(p): 'action : IF fmla LCB action RCB ELSE action' p[0] = IfAction(p[2], p[4], p[7]) p[0].lineno = get_lineno(p, 1)
def p_action_if_somefmla_lcb_action_rcb(p): 'action : IF somefmla sequence' p[0] = IfAction(p[2], fix_if_part(p[2], p[3])) p[0].lineno = get_lineno(p, 1)
def p_action_if_somefmla_lcb_action_rcb_else_LCB_action_RCB(p): 'action : IF somefmla sequence ELSE action' p[0] = IfAction(p[2], fix_if_part(p[2], p[3]), p[5]) p[0].lineno = get_lineno(p, 1)
def p_action_if_fmla_lcb_action_rcb(p): 'action : IF fmla sequence' p[0] = IfAction(p[2], p[3]) p[0].lineno = get_lineno(p, 1)
def p_action_if_fmla_lcb_action_rcb_else_LCB_action_RCB(p): 'action : IF fmla sequence ELSE action' p[0] = IfAction(p[2], p[3], p[5]) p[0].lineno = get_lineno(p, 1)
def p_action_if_somefmla_lcb_action_rcb_else_LCB_action_RCB(p): 'action : IF somefmla LCB action RCB ELSE action' p[0] = IfAction(p[2],fix_if_part(p[2],p[4]),p[7]) p[0].lineno = get_lineno(p,1)
def p_action_if_somefmla_lcb_action_rcb(p): 'action : IF somefmla LCB action RCB' p[0] = IfAction(p[2],fix_if_part(p[2],p[4])) p[0].lineno = get_lineno(p,1)
def p_action_if_fmla_lcb_action_rcb_else_LCB_action_RCB(p): 'action : IF fmla LCB action RCB ELSE action' p[0] = IfAction(p[2],p[4],p[7]) p[0].lineno = p.lineno(1)
def p_action_if_fmla_lcb_action_rcb(p): 'action : IF fmla LCB action RCB' p[0] = IfAction(p[2],p[4]) p[0].lineno = p.lineno(1)
def scenario(self, scen): init_tokens = set(p.rep for p in scen.args[0].args) transs_by_action = defaultdict(list) for tr in scen.args[1:]: transs_by_action[tr.args[2].args[1].args[0].rep].append(tr) for (place_name, lineno) in scen.places(): sym = find_symbol(place_name) iname = place_name + '[init]' iact = AssignAction( sym, ivy_logic.And() if (place_name in init_tokens) else ivy_logic.Or()) iact.formal_params = [] iact.formal_returns = [] iact.lineno = scen.lineno self.mod.actions[iname] = iact self.mixin( ivy_ast.MixinAfterDef(ivy_ast.Atom(iname), ivy_ast.Atom('init'))) for actname, trs in transs_by_action.iteritems(): choices = [] params = None afters = [] for tr in trs: scmix = tr.args[2] is_after = isinstance(scmix, ivy_ast.ScenarioAfterMixin) df = scmix.args[1] body = compile_action_def(df, self.mod.sig) seq = [] if not is_after: for p in tr.args[0].args: seq.append(AssumeAction(find_symbol(p.rep))) for p in tr.args[0].args: seq.append( AssignAction(find_symbol(p.rep), ivy_logic.Or())) for p in tr.args[1].args: seq.append( AssignAction(find_symbol(p.rep), ivy_logic.And())) seq.append(body) seq = Sequence(*seq) else: for p in tr.args[0].args: seq.append( AssignAction(find_symbol(p.rep), ivy_logic.Or())) for p in tr.args[1].args: seq.append( AssignAction(find_symbol(p.rep), ivy_logic.And())) seq.append(body) seq = Sequence(*seq) seq = IfAction( And(*[find_symbol(p.rep) for p in tr.args[0].args]), seq) if params is None: params = body.formal_params returns = body.formal_returns mixer = scmix.args[0] mixee = scmix.args[1].args[0] else: aparams = df.formal_params + df.formal_returns subst = dict(zip(aparams, params + returns)) seq = substitute_constants_ast(seq, subst) seq.lineno = tr.lineno if not is_after: choices.append(seq) else: afters.append(seq) if choices: choice = BalancedChoice(choices) choice.lineno = choices[0].lineno choice.formal_params = params choice.formal_returns = returns self.mod.actions[mixer.rep] = choice self.mixin(ivy_ast.MixinBeforeDef(mixer, mixee)) if afters: choice = Sequence(*afters) choice.lineno = afters[0].lineno choice.formal_params = params choice.formal_returns = returns self.mod.actions[mixer.rep] = choice self.mixin(ivy_ast.MixinAfterDef(mixer, mixee))