2 * FML interpreter. Europagate, 1995
5 * Revision 1.1 1995/02/09 14:33:37 adam
6 * Split source fml.c and define relevant build-in functions in separate
7 * files. New operators mult, div, not, llen implemented.
17 static struct fml_node *fml_exec_gt (Fml fml, struct fml_node *l,
20 int left_val, right_val;
22 fml_lr_values (fml, l, &left_val, r, &right_val);
23 if (left_val > right_val)
25 fn = fml_node_alloc (fml);
27 fn->p[0] = fml_atom_alloc (fml, "1");
34 static struct fml_node *fml_exec_lt (Fml fml, struct fml_node *l,
37 int left_val, right_val;
39 fml_lr_values (fml, l, &left_val, r, &right_val);
40 if (left_val < right_val)
42 fn = fml_node_alloc (fml);
44 fn->p[0] = fml_atom_alloc (fml, "1");
51 static struct fml_node *fml_exec_eq (Fml fml, struct fml_node *l,
54 int left_val, right_val;
56 fml_lr_values (fml, l, &left_val, r, &right_val);
57 if (left_val == right_val)
59 fn = fml_node_alloc (fml);
61 fn->p[0] = fml_atom_alloc (fml, "1");
68 static struct fml_node *fml_exec_ne (Fml fml, struct fml_node *l,
71 int left_val, right_val;
73 fml_lr_values (fml, l, &left_val, r, &right_val);
74 if (left_val != right_val)
76 fn = fml_node_alloc (fml);
78 fn->p[0] = fml_atom_alloc (fml, "1");
85 static struct fml_node *fml_exec_le (Fml fml, struct fml_node *l,
88 int left_val, right_val;
90 fml_lr_values (fml, l, &left_val, r, &right_val);
91 if (left_val <= right_val)
93 fn = fml_node_alloc (fml);
95 fn->p[0] = fml_atom_alloc (fml, "1");
102 static struct fml_node *fml_exec_ge (Fml fml, struct fml_node *l,
105 int left_val, right_val;
107 fml_lr_values (fml, l, &left_val, r, &right_val);
108 if (left_val >= right_val)
110 fn = fml_node_alloc (fml);
112 fn->p[0] = fml_atom_alloc (fml, "1");
119 static struct fml_node *fml_exec_and (Fml fml, struct fml_node *l,
124 fml_node_delete (fml, l);
127 fml_node_delete (fml, l);
128 fml_node_delete (fml, r);
132 static struct fml_node *fml_exec_or (Fml fml, struct fml_node *l,
137 fml_node_delete (fml, l);
143 static struct fml_node *fml_exec_not (Fml fml, struct fml_node **lp,
147 fml_cmd_lex (lp, tp);
149 fn = fml_expr_term (fml, lp, tp);
152 fml_node_delete (fml, fn);
155 fn = fml_node_alloc (fml);
157 fn->p[0] = fml_atom_alloc (fml, "1");
161 void fml_rel_init (Fml fml)
163 struct fml_sym_info *sym_info;
165 sym_info = fml_sym_add (fml->sym_tab, "gt");
166 sym_info->kind = FML_CBINARY;
167 sym_info->binary = fml_exec_gt;
168 sym_info = fml_sym_add (fml->sym_tab, "lt");
169 sym_info->kind = FML_CBINARY;
170 sym_info->binary = fml_exec_lt;
171 sym_info = fml_sym_add (fml->sym_tab, "eq");
172 sym_info->kind = FML_CBINARY;
173 sym_info->binary = fml_exec_eq;
175 sym_info = fml_sym_add (fml->sym_tab, "ge");
176 sym_info->kind = FML_CBINARY;
177 sym_info->binary = fml_exec_ge;
178 sym_info = fml_sym_add (fml->sym_tab, "le");
179 sym_info->kind = FML_CBINARY;
180 sym_info->binary = fml_exec_le;
181 sym_info = fml_sym_add (fml->sym_tab, "ne");
182 sym_info->kind = FML_CBINARY;
183 sym_info->binary = fml_exec_ne;
185 sym_info = fml_sym_add (fml->sym_tab, "and");
186 sym_info->kind = FML_CBINARY;
187 sym_info->binary = fml_exec_and;
188 sym_info = fml_sym_add (fml->sym_tab, "or");
189 sym_info->kind = FML_CBINARY;
190 sym_info->binary = fml_exec_or;
192 sym_info = fml_sym_add (fml->sym_tab, "not");
193 sym_info->kind = FML_CPREFIX;
194 sym_info->prefix = fml_exec_not;