Beispiel #1
0
def fun_macro_grammar(klass1, klass2):
  return (
  # fun. a(x)[...],  fun. a(x) <= at[...][...]
    (getattr(vv.name)+
     any(~call(__.args) +assign(__.args, getvalue_default(__.args, ()))
          + some(getitem_to_list(__.body), __.body, __.bodies), 
          (__.args, __.bodies), vv.rules)
        +eoi+make_fun1(vv.name, vv.rules, klass2))
  # fun. a(x) >= [...],  fun. a(x) <= at[...][...]
  | (getattr(vv.name)+call(vv.args)+ge(vv.body)+eoi
     +make_fun2(vv.name,vv.args, vv.body, klass2))
  # fun. a(x) <= [...],  fun. a(x) <= at[...][...]
  | (getattr(vv.name)+call(vv.args)+le(vv.body)+eoi
     +make_fun3(vv.name,vv.args, vv.body, klass2))
  #  fun. a== at(..)[...]
  | (getattr(vv.name)+eq(vv.rules)+eoi
     +make_fun4(vv.name, vv.rules, klass1))
  #  fun. a>= at(..)[...]
  | (getattr(vv.name)+ge(vv.rules)+eoi+make_fun5(vv.name,vv.rules, klass2))
  #  fun. a<= at(..)[...]
  | (getattr(vv.name)+le(vv.rules)+eoi+make_fun6(vv.name,vv.rules, klass2))
  #  fun(args) [...](args)[...][...]
  | (some(may(call(__.args)) +assign(__.args, getvalue_default(__.args, ()))
          + some(getitem_to_list(__.body), __.body, __.bodies), 
          (__.args, __.bodies), vv.rules)
        +eoi+make_fun7(vv.rules, klass1))
  #   - fun.a/3,
  | (getattr(vv.name)+neg+div(vv.arity)+eoi
     +pycall(abolish, getvar(vv.name), vv.arity))
  #- fun.a(x),
  | (getattr(vv.name)+call(vv.args)+neg+eoi
     +make_fun8(vv.name, vv.args, klass2)) #retractall
  #- fun.a(x)[1],
##  | (getattr(vv.name)+call(vv.args)+getitem(vv.index)+neg+assign(result, retract(vv.name, vv.args)))
  )
Beispiel #2
0
def fun_macro_grammar(klass1, klass2):
    return (
        # fun. a(x)[...],  fun. a(x) <= at[...][...]
        (getattr(vv.name) + any(
            ~call(__.args) + assign(__.args, getvalue_default(__.args, ())) +
            some(getitem_to_list(__.body), __.body, __.bodies),
            (__.args, __.bodies), vv.rules) + eoi +
         make_fun1(vv.name, vv.rules, klass2))
        # fun. a(x) >= [...],  fun. a(x) <= at[...][...]
        | (getattr(vv.name) + call(vv.args) + ge(vv.body) + eoi +
           make_fun2(vv.name, vv.args, vv.body, klass2))
        # fun. a(x) <= [...],  fun. a(x) <= at[...][...]
        | (getattr(vv.name) + call(vv.args) + le(vv.body) + eoi +
           make_fun3(vv.name, vv.args, vv.body, klass2))
        #  fun. a== at(..)[...]
        | (getattr(vv.name) + eq(vv.rules) + eoi +
           make_fun4(vv.name, vv.rules, klass1))
        #  fun. a>= at(..)[...]
        | (getattr(vv.name) + ge(vv.rules) + eoi +
           make_fun5(vv.name, vv.rules, klass2))
        #  fun. a<= at(..)[...]
        | (getattr(vv.name) + le(vv.rules) + eoi +
           make_fun6(vv.name, vv.rules, klass2))
        #  fun(args) [...](args)[...][...]
        | (some(
            may(call(__.args)) + assign(__.args, getvalue_default(__.args,
                                                                  ())) +
            some(getitem_to_list(__.body), __.body, __.bodies),
            (__.args, __.bodies), vv.rules) + eoi +
           make_fun7(vv.rules, klass1))
        #   - fun.a/3,
        | (getattr(vv.name) + neg + div(vv.arity) + eoi +
           pycall(abolish, getvar(vv.name), vv.arity))
        #- fun.a(x),
        | (getattr(vv.name) + call(vv.args) + neg + eoi +
           make_fun8(vv.name, vv.args, klass2))  #retractall
        #- fun.a(x)[1],
        ##  | (getattr(vv.name)+call(vv.args)+getitem(vv.index)+neg+assign(result, retract(vv.name, vv.args)))
    )
Beispiel #3
0
    return special.CaseForm(preparse(test[0]), case_dict, els_clause)


of_fun = attr_call('of')

# case(x).of(1)[write(1)].of(2,3)[write(4)].els[write(5)]
case = element(
    'case',
    call(vv.test) + (
        #.of(1)[write(1)].of(2,3)[write(4)].els[write(5)]
        (some(
            of_fun(__.values) + getitem_to_list(__.clause),
            (__.values, __.clause), vv.clauses) +
         may(_els + getitem_to_list(vv.els)) + eoi + make_case(
             vv.test,
             list_tail(vv.clauses, pytuple(CASE_ELS, getvalue_default(
                 vv.els)))))
        #/{1:[write(1)],2:[write(4)],3:[write(4)], els:[write(5)]}
        ##  | div(vv.clauses)+eoi+make_case(vv.test, items(vv.clauses))
    ))
els = CASE_ELS


@builtin.function('make_loop')
def make_loop(body):
    return special.LoopForm(preparse(body))


@builtin.function('make_loop_times')
def make_loop_times(body, times):
    return special.LoopTimesForm(preparse(times[0]), preparse(body))
Beispiel #4
0
    if case is CASE_ELS: 
      els_clause = preparse(clause) if clause is not None else None
    else:
      clause = preparse(clause)
      for x in case: case_dict[x] = clause
  return special.CaseForm(preparse(test[0]), case_dict, els_clause)

of_fun = attr_call('of')

# case(x).of(1)[write(1)].of(2,3)[write(4)].els[write(5)]
case = element('case',
  call(vv.test)+(
  #.of(1)[write(1)].of(2,3)[write(4)].els[write(5)]
    (some(of_fun(__.values)+getitem_to_list(__.clause),(__.values,__.clause), vv.clauses)
     +may(_els+getitem_to_list(vv.els))+eoi
    +make_case(vv.test, list_tail(vv.clauses, pytuple(CASE_ELS, getvalue_default(vv.els)))))
  #/{1:[write(1)],2:[write(4)],3:[write(4)], els:[write(5)]}
##  | div(vv.clauses)+eoi+make_case(vv.test, items(vv.clauses))
  ))
els = CASE_ELS

@builtin.function('make_loop')
def make_loop(body): 
  return special.LoopForm(preparse(body))

@builtin.function('make_loop_times')
def make_loop_times(body, times):
  return special.LoopTimesForm(preparse(times[0]), preparse(body))

@builtin.function('make_loop_when')
def make_loop_when(body, test):