2 * FML interpreter. Europagate, 1995
5 * Revision 1.4 1995/02/23 08:32:05 adam
8 * Revision 1.2 1995/02/10 15:50:55 adam
9 * MARC interface implemented. Minor bugs fixed. fmltest can
10 * be used to format single MARC records. New function '\list'
13 * Revision 1.1 1995/02/09 14:33:37 adam
14 * Split source fml.c and define relevant build-in functions in separate
15 * files. New operators mult, div, not, llen implemented.
25 static struct fml_node *fml_exec_indx (Fml fml, struct fml_node *l,
28 struct fml_node *list = l;
32 if (!l || !r || !r->is_atom)
34 fml_node_delete (fml, l);
35 fml_node_delete (fml, r);
38 indx = fml_atom_val (r->p[0]);
39 fml_node_delete (fml, r);
40 while (--indx >= 1 && list)
44 else if (list->is_atom)
46 fn = fml_node_alloc (fml);
48 fn->p[0] = list->p[0];
57 fml_node_delete (fml, l);
61 static struct fml_node *fml_exec_len (Fml fml, struct fml_node **lp,
71 for (fn = tp->sub; fn; fn = fn->p[1])
74 else if (tp->kind == 'e')
76 struct fml_sym_info *info;
78 info = fml_sym_lookup (fml->sym_tab, tp->tokenbuf);
80 for (fn = info->body; fn; fn = fn->p[1])
86 sprintf (arg, "%d", len);
87 fn = fml_node_alloc (fml);
89 fn->p[0] = fml_atom_alloc (fml, arg);
94 static struct fml_node *fml_exec_list (Fml fml, struct fml_node **lp,
97 struct fml_node *fn = NULL;
101 fn = fml_node_copy (fml, tp->sub);
104 fn = fml_node_alloc (fml);
106 fn->p[0] = fml_atom_alloc (fml, tp->tokenbuf);
108 fml_cmd_lex (lp, tp);
112 void fml_list_init (Fml fml)
114 struct fml_sym_info *sym_info;
116 sym_info = fml_sym_add (fml->sym_tab, "index");
117 sym_info->kind = FML_CBINARY;
118 sym_info->binary = fml_exec_indx;
120 sym_info = fml_sym_add (fml->sym_tab, "llen");
121 sym_info->kind = FML_CPREFIX;
122 sym_info->prefix = fml_exec_len;
124 sym_info = fml_sym_add (fml->sym_tab, "list");
125 sym_info->kind = FML_CPREFIX;
126 sym_info->prefix = fml_exec_list;