2 * FML interpreter. Europagate, 1995
5 * Revision 1.4 1995/02/10 18:15:53 adam
6 * FML function 'strcmp' implemented. This function can be used to
7 * test for existence of MARC fields.
9 * Revision 1.3 1995/02/10 15:50:57 adam
10 * MARC interface implemented. Minor bugs fixed. fmltest can
11 * be used to format single MARC records. New function '\list'
14 * Revision 1.2 1995/02/07 16:09:24 adam
15 * The \ character is no longer INCLUDED when terminating a token.
16 * Major changes in tokenization routines. Bug fixes in expressions
17 * with lists (fml_sub0).
19 * Revision 1.1.1.1 1995/02/06 13:48:10 adam
20 * First version of the FML interpreter. It's slow and memory isn't
21 * freed properly. In particular, the FML nodes aren't released yet.
32 static char lex_buf[FML_MAX_TOKEN];
34 static void lexer (Fml fml);
36 struct fml_node *fml_group (Fml fml);
38 struct fml_node *fml_tokenize (Fml fml)
42 look_char = (*fml->read_func)();
49 if (look_char != fml->eof_mark)
51 fprintf (stderr, "Ill formed parantheses");
57 void fml_pr_list (struct fml_node *p)
66 fml_atom_str (p->p[0], buf);
72 fml_pr_list (p->p[0]);
79 struct fml_node *fml_group (Fml fml)
81 struct fml_node *ptr0 = NULL, *ptr1, *ptr2;
90 ptr2 = fml_node_alloc (fml);
95 ptr2->p[0] = fml_atom_alloc (fml, lex_buf);
98 else if (look_type == '{')
100 struct fml_node *sptr = fml_group (fml);
103 ptr2 = fml_node_alloc (fml);
113 ptr2 = fml_node_alloc (fml);
129 static void lexer (Fml fml)
134 if (look_char == fml->eof_mark)
139 else if (look_char == fml->comment_char)
142 look_char = (*fml->read_func)();
143 while (look_char != '\n' && look_char != fml->eof_mark);
147 if (!strchr (fml->white_chars, look_char))
149 look_char = (*fml->read_func)();
152 if (look_char == '{')
155 look_char = (*fml->read_func)();
157 else if (look_char == '}')
160 look_char = (*fml->read_func)();
162 else if (look_char == '\'')
165 look_char = (*fml->read_func)();
166 while (look_char != fml->eof_mark && look_char != '\'')
168 lex_buf[off++] = look_char;
169 if (look_char == '\\')
171 look_char = (*fml->read_func)();
175 lex_buf[off-1] = '\n';
178 lex_buf[off-1] = '\n';
181 lex_buf[off-1] = '\'';
184 lex_buf[off-1] = look_char;
187 look_char = (*fml->read_func)();
191 if (look_char == '\'')
192 look_char = (*fml->read_func)();
199 lex_buf[off++] = look_char;
200 look_char = (*fml->read_func)();
201 } while (look_char != fml->eof_mark
202 && !strchr (fml->white_chars, look_char)
203 && look_char != '{' && look_char != '}');
210 if (look_type == 'a')
211 printf ("[%s]", lex_buf);
213 printf ("[%c]", look_type);