2 * FML interpreter. Europagate, 1995
5 * Revision 1.2 1995/02/10 15:50:55 adam
6 * MARC interface implemented. Minor bugs fixed. fmltest can
7 * be used to format single MARC records. New function '\list'
10 * Revision 1.1 1995/02/09 14:33:37 adam
11 * Split source fml.c and define relevant build-in functions in separate
12 * files. New operators mult, div, not, llen implemented.
22 static struct fml_node *fml_exec_indx (Fml fml, struct fml_node *l,
25 struct fml_node *list = l;
29 if (!l || !r || !r->is_atom)
31 fml_node_delete (fml, l);
32 fml_node_delete (fml, r);
35 indx = fml_atom_val (r->p[0]);
36 fml_node_delete (fml, r);
37 while (--indx >= 1 && list)
41 else if (list->is_atom)
43 fn = fml_node_alloc (fml);
45 fn->p[0] = list->p[0];
54 fml_node_delete (fml, l);
58 static struct fml_node *fml_exec_len (Fml fml, struct fml_node **lp,
68 for (fn = tp->sub; fn; fn = fn->p[1])
71 else if (tp->kind == 'e')
73 struct fml_sym_info *info;
75 info = fml_sym_lookup (fml->sym_tab, tp->tokenbuf);
77 for (fn = info->body; fn; fn = fn->p[1])
83 sprintf (arg, "%d", len);
84 fn = fml_node_alloc (fml);
86 fn->p[0] = fml_atom_alloc (fml, arg);
91 static struct fml_node *fml_exec_list (Fml fml, struct fml_node **lp,
94 struct fml_node *fn = NULL;
98 fn = fml_node_copy (fml, tp->sub);
101 fn = fml_node_alloc (fml);
103 fn->p[0] = fml_atom_alloc (fml, tp->tokenbuf);
105 fml_cmd_lex (lp, tp);
109 void fml_list_init (Fml fml)
111 struct fml_sym_info *sym_info;
113 sym_info = fml_sym_add (fml->sym_tab, "index");
114 sym_info->kind = FML_CBINARY;
115 sym_info->binary = fml_exec_indx;
117 sym_info = fml_sym_add (fml->sym_tab, "llen");
118 sym_info->kind = FML_CPREFIX;
119 sym_info->prefix = fml_exec_len;
121 sym_info = fml_sym_add (fml->sym_tab, "list");
122 sym_info->kind = FML_CPREFIX;
123 sym_info->prefix = fml_exec_list;