20 add(
"tail(%s)", +[](
S s) ->
S {
28 S& a = vms->
stack<
S>().topref();
35 char b = vms->
getpop<
char>();
36 S& a = vms->
stack<
S>().topref();
45 add(
"(%s==%s)", +[](
S x,
S y) ->
bool {
return x==y; });
46 add(
"empty(%s)", +[](
S x) ->
bool {
return x.length()==0; });
48 add(
"insert(%s,%s)", +[](
S x,
S y) ->
S {
49 size_t l = x.length();
57 S out = x.substr(0, pos);
59 out.append(x.substr(pos));
76 StrSet s; s.insert(x);
return s;
92 std::set_difference(s.begin(), s.end(), x.begin(), x.end(), std::inserter(output, output.begin()));
98 add(
"and(%s,%s)", Builtins::And<MyGrammar>);
99 add(
"or(%s,%s)", Builtins::Or<MyGrammar>);
100 add(
"not(%s)", Builtins::Not<MyGrammar>);
104 add(
"if(%s,%s,%s)", Builtins::If<MyGrammar,S>);
105 add(
"if(%s,%s,%s)", Builtins::If<MyGrammar,StrSet>);
106 add(
"if(%s,%s,%s)", Builtins::If<MyGrammar,double>);
109 add(
"sample(%s)", Builtins::Sample<MyGrammar, S>,
CONSTANT_P);
112 for(
int a=1;a<=pdenom/2;a++) {
113 std::string s =
str(a/std::gcd(a,pdenom)) +
"/" +
str(pdenom/std::gcd(a,pdenom));
122 add(
"F%s(%s)" , Builtins::LexiconRecurse<MyGrammar,int>, 1./2.);
123 add(
"Fm%s(%s)", Builtins::LexiconMemRecurse<MyGrammar,int>, 1./2.);
Definition: VMSRuntimeError.h:13
Definition: VirtualMachineState.h:46
Definition: Singleton.h:6
std::string S
Definition: Main.cpp:28
T getpop()
Retrieves and pops the element of type T from the stack.
Definition: VirtualMachineState.h:145
std::set< S > StrSet
Definition: Main.cpp:15
std::string str(BindingTree *t)
Definition: BindingTree.h:195
VMSStack< T > & stack()
Returns a reference to the stack (of a given type)
Definition: VirtualMachineState.h:125
Grammar< BindingTree *, bool, S, POS, int, bool, BindingTree *, TSeq, TtoT, TtoTSeq, TtoBool, TxTtoBool >::add_terminal void add_terminal(std::string fmt, T x, double p=1.0, Op o=Op::Standard, int a=0)
Add a variable that is NOT A function – simplification for adding alphabets etc. This just wraps stu...
Definition: Grammar.h:435
const std::string EMPTY_STRING
Definition: Strings.h:17
Definition: MyGrammar.h:72
MyGrammar()
Definition: MyGrammar.h:79
size_t max_length
Definition: Main.cpp:20
size_t max_setsize
Definition: Main.cpp:21
const double CONSTANT_P
Definition: Main.cpp:42
Grammar< BindingTree *, bool, S, POS, int, bool, BindingTree *, TSeq, TtoT, TtoTSeq, TtoBool, TxTtoBool >::add void add(std::string fmt, Primitive< T, args... > &b, double p=1.0, int a=0)
Definition: Grammar.h:312
S alphabet
Definition: Main.cpp:19
A grammar stores all of the rules associated with any kind of nonterminal and permits us to sample as...