46 const std::string fmt,
47 std::initializer_list<nonterminal_t> c,
51 nt(rt), format(fmt), N(c.size()), p(_p), fptr(f), op(o), arg(a), child_types(c) {
57 hash_combine(my_hash, (
size_t)nt);
59 for(
size_t k=0;k<
N;k++)
60 hash_combine(my_hash, (
size_t)op, (
size_t)child_types[k], (
size_t) arg);
62 for(
auto& thechar : format)
63 hash_combine(my_hash, (
size_t)thechar );
67 assert(ChildStr.substr(0,1) == SilentChildStr.substr(0,1));
68 if(N !=
count(fmt, ChildStr.substr(0,1))) {
69 CERR "*** Wrong number of format string arguments in " << fmt
ENDL;
93 assert(arg==0 &&
"*** You have specified a when arg != 0 -- this is probably a mistake.");
102 auto operator<=>(
const Rule& r)
const {
112 if( (N==0) != (r.
N==0) )
113 return (r.
N==0) <=> (N==0);
117 return fp_ordering(r.
p, p);
119 else if(format != r.
format)
120 return format <=> r.
format;
132 if(not (nt==r.
nt and fptr == r.
fptr and op ==r.
op and format==r.
format and N==r.
N and p==r.
p))
return false;
133 for(
size_t i=0;i<
N;i++) {
134 if(child_types[i] != r.
child_types[i])
return false;
159 assert(i <= N &&
"*** Cannot get the type of something out of range");
160 return child_types[i];
168 std::string out =
"[RULE " + format +
", ";
169 for(
size_t i =0;i<
N;i++) {
170 out +=
str(child_types[i]) +
"x";
172 if(N > 0) out = out.erase(out.size()-1);
173 out +=
"->" +
str(nt) +
", p\u221D" +
str(p) +
"]";
int arg
Definition: Rule.h:35
bool is_a(Op o) const
Definition: Rule.h:74
nonterminal_t type(size_t i) const
Definition: Rule.h:152
size_t count(const std::string &str, const std::string &sub)
Definition: Strings.h:153
Definition: Instruction.h:20
static const std::string ChildStr
Definition: Rule.h:24
auto & get_child_types() const
Definition: Rule.h:163
f here is a point to a void(VirtualMachineState_t* vms, int arg), where arg is just a supplemental ar...
size_t get_hash() const
Definition: Rule.h:139
const Rule * NullRule
Definition: Rule.h:186
std::string str(BindingTree *t)
Definition: BindingTree.h:195
size_t N
Definition: Rule.h:29
std::ostream & operator<<(std::ostream &o, const Rule &r)
Definition: Rule.h:179
std::string format
Definition: Rule.h:28
#define CERR
Definition: IO.h:23
bool is_recursive() const
Definition: Rule.h:78
Rule(const nonterminal_t rt, void *f, const std::string fmt, std::initializer_list< nonterminal_t > c, double _p=1.0, Op o=Op::Standard, int a=0)
Definition: Rule.h:44
std::size_t my_hash
Definition: Rule.h:40
std::vector< nonterminal_t > child_types
Definition: Rule.h:36
unsigned short nonterminal_t
Definition: Nonterminal.h:4
Op op
Definition: Rule.h:34
double p
Definition: Rule.h:30
#define ENDL
Definition: IO.h:21
bool operator==(const Rule &r) const
Definition: Rule.h:125
static const std::string SilentChildStr
Definition: Rule.h:25
void * fptr
Definition: Rule.h:33
nonterminal_t nt
Definition: Rule.h:27
bool is_terminal() const
Definition: Rule.h:143
Instruction makeInstruction(int a) const
Definition: Rule.h:92
std::string string() const
Definition: Rule.h:167
Instruction makeInstruction() const
Definition: Rule.h:97