12 extern volatile sig_atomic_t
CTRL_C;
30 template<
typename Grammar_t>
34 template<
typename Grammar_t>
38 template<
typename Grammar_t>
42 template<
typename Grammar_t>
60 add(
"I", CL_I<SKGrammar>);
61 add(
"S", CL_S<SKGrammar>);
62 add(
"K", CL_K<SKGrammar>);
63 add(
"(%s %s)", CL_Apply<SKGrammar>, 2.0);
97 if(remaining_calls-- == 0)
104 if(NC == 2 and not n.
label.has_value()) {
105 if(n.
child(0).get_label() ==
"I"){
106 assert(n.
child(0).nchildren() == 0);
107 auto x = std::move(n.
child(1));
112 else if(n.
child(0).nchildren() == 2 and
113 n.
child(0).child(0).get_label() ==
"K") {
114 assert(n.
child(0).child(0).nchildren() == 0);
115 auto x = std::move(n.
child(0).child(1));
120 else if(n.
child(0).nchildren() == 2 and
121 n.
child(0).child(0).nchildren() == 2 and
122 n.
child(0).child(0).child(0).get_label() ==
"S") {
123 assert(n.
child(0).child(0).child(0).nchildren() == 0);
126 auto x = std::move(n.
child(0).child(0).child(1));
127 auto y = std::move(n.
child(0).child(1));
128 auto z = std::move(n.
child(1));
147 auto x = std::move(n.
child(0));
160 int remaining_calls = 256;
161 reduce(n,remaining_calls);
183 assert(n.
label.has_value());
192 assert(rapp !=
nullptr);
208 if(n.
label.has_value() and m.factors.contains(n.
label.value())) {
209 auto v = m.at(n.
label.value()).get_value();
Definition: Combinators.h:75
The Primitive type just stores a function pointer and an Op command.
This is the return type of parsing S-expressions. It contains an optional label and typically we be c...
Combinators::SKGrammar skgrammar
SExpression::SExpNode NodeToSExpNode(const Node &n)
Definition: Combinators.h:164
decltype(children) & get_children()
Definition: BaseNode.h:168
Primitive< Combinators::CL > CL_I(Op::CL_I, BUILTIN_LAMBDA {assert(false);})
const std::string & format() const
Definition: Node.h:74
void set_child(const size_t i, this_t &n)
Definition: BaseNode.h:283
Definition: Combinators.h:15
Node SExpNodeToNode(const SExpression::SExpNode &n)
Definition: Combinators.h:181
Definition: Primitive.h:13
void reduce(SExpression::SExpNode &n, int &remaining_calls)
Combinator reduction, assuming that n is a SExpNode.
Definition: Combinators.h:82
bool operator<(const CL &other) const
Definition: Combinators.h:25
Definition: SExpression.h:20
void substitute(SExpression::SExpNode &n, const L &m)
Definition: Combinators.h:205
Definition: Combinators.h:53
Primitive< Combinators::CL > CL_S(Op::CL_S, BUILTIN_LAMBDA {assert(false);})
volatile sig_atomic_t CTRL_C
Definition: Combinators.h:23
cl_void()
Definition: Combinators.h:20
A Node is the primary internal representation for a program – it recursively stores a rule and the a...
Definition: Combinators.h:19
this_t & child(const size_t i)
Definition: BaseNode.h:175
const Rule * rule
Definition: Node.h:32
std::optional< std::string > label
Definition: SExpression.h:21
void set_child(const size_t i, Node &n)
Definition: Node.h:88
#define BUILTIN_LAMBDA
Definition: Builtins.h:9
Primitive< Combinators::CL > CL_K(Op::CL_K, BUILTIN_LAMBDA {assert(false);})
Primitive< Combinators::CL, Combinators::CL, Combinators::CL > CL_Apply(Op::CL_Apply, BUILTIN_LAMBDA {assert(false);})
SKGrammar()
Definition: Combinators.h:58
virtual Rule * get_rule(const nonterminal_t nt, size_t k) const
Definition: Grammar.h:489
Combinators::ReductionException reduction_exception
size_t nchildren() const
Definition: BaseNode.h:208
A grammar stores all of the rules associated with any kind of nonterminal and permits us to sample as...