2 * FML interpreter. Europagate, 1995
5 * Revision 1.3 1995/02/23 08:32:06 adam
8 * Revision 1.1 1995/02/09 14:33:37 adam
9 * Split source fml.c and define relevant build-in functions in separate
10 * files. New operators mult, div, not, llen implemented.
20 static struct fml_node *fml_exec_gt (Fml fml, struct fml_node *l,
23 int left_val, right_val;
25 fml_lr_values (fml, l, &left_val, r, &right_val);
26 if (left_val > right_val)
28 fn = fml_node_alloc (fml);
30 fn->p[0] = fml_atom_alloc (fml, "1");
37 static struct fml_node *fml_exec_lt (Fml fml, struct fml_node *l,
40 int left_val, right_val;
42 fml_lr_values (fml, l, &left_val, r, &right_val);
43 if (left_val < right_val)
45 fn = fml_node_alloc (fml);
47 fn->p[0] = fml_atom_alloc (fml, "1");
54 static struct fml_node *fml_exec_eq (Fml fml, struct fml_node *l,
57 int left_val, right_val;
59 fml_lr_values (fml, l, &left_val, r, &right_val);
60 if (left_val == right_val)
62 fn = fml_node_alloc (fml);
64 fn->p[0] = fml_atom_alloc (fml, "1");
71 static struct fml_node *fml_exec_ne (Fml fml, struct fml_node *l,
74 int left_val, right_val;
76 fml_lr_values (fml, l, &left_val, r, &right_val);
77 if (left_val != right_val)
79 fn = fml_node_alloc (fml);
81 fn->p[0] = fml_atom_alloc (fml, "1");
88 static struct fml_node *fml_exec_le (Fml fml, struct fml_node *l,
91 int left_val, right_val;
93 fml_lr_values (fml, l, &left_val, r, &right_val);
94 if (left_val <= right_val)
96 fn = fml_node_alloc (fml);
98 fn->p[0] = fml_atom_alloc (fml, "1");
105 static struct fml_node *fml_exec_ge (Fml fml, struct fml_node *l,
108 int left_val, right_val;
110 fml_lr_values (fml, l, &left_val, r, &right_val);
111 if (left_val >= right_val)
113 fn = fml_node_alloc (fml);
115 fn->p[0] = fml_atom_alloc (fml, "1");
122 static struct fml_node *fml_exec_and (Fml fml, struct fml_node *l,
127 fml_node_delete (fml, l);
130 fml_node_delete (fml, l);
131 fml_node_delete (fml, r);
135 static struct fml_node *fml_exec_or (Fml fml, struct fml_node *l,
140 fml_node_delete (fml, l);
146 static struct fml_node *fml_exec_not (Fml fml, struct fml_node **lp,
150 fml_cmd_lex (lp, tp);
152 fn = fml_expr_term (fml, lp, tp);
155 fml_node_delete (fml, fn);
158 fn = fml_node_alloc (fml);
160 fn->p[0] = fml_atom_alloc (fml, "1");
164 void fml_rel_init (Fml fml)
166 struct fml_sym_info *sym_info;
168 sym_info = fml_sym_add (fml->sym_tab, "gt");
169 sym_info->kind = FML_CBINARY;
170 sym_info->binary = fml_exec_gt;
171 sym_info = fml_sym_add (fml->sym_tab, "lt");
172 sym_info->kind = FML_CBINARY;
173 sym_info->binary = fml_exec_lt;
174 sym_info = fml_sym_add (fml->sym_tab, "eq");
175 sym_info->kind = FML_CBINARY;
176 sym_info->binary = fml_exec_eq;
178 sym_info = fml_sym_add (fml->sym_tab, "ge");
179 sym_info->kind = FML_CBINARY;
180 sym_info->binary = fml_exec_ge;
181 sym_info = fml_sym_add (fml->sym_tab, "le");
182 sym_info->kind = FML_CBINARY;
183 sym_info->binary = fml_exec_le;
184 sym_info = fml_sym_add (fml->sym_tab, "ne");
185 sym_info->kind = FML_CBINARY;
186 sym_info->binary = fml_exec_ne;
188 sym_info = fml_sym_add (fml->sym_tab, "and");
189 sym_info->kind = FML_CBINARY;
190 sym_info->binary = fml_exec_and;
191 sym_info = fml_sym_add (fml->sym_tab, "or");
192 sym_info->kind = FML_CBINARY;
193 sym_info->binary = fml_exec_or;
195 sym_info = fml_sym_add (fml->sym_tab, "not");
196 sym_info->kind = FML_CPREFIX;
197 sym_info->prefix = fml_exec_not;