2 * FML interpreter. Europagate, 1995
5 * Revision 1.6 1995/02/23 08:32:07 adam
8 * Revision 1.4 1995/02/10 18:15:53 adam
9 * FML function 'strcmp' implemented. This function can be used to
10 * test for existence of MARC fields.
12 * Revision 1.3 1995/02/10 15:50:57 adam
13 * MARC interface implemented. Minor bugs fixed. fmltest can
14 * be used to format single MARC records. New function '\list'
17 * Revision 1.2 1995/02/07 16:09:24 adam
18 * The \ character is no longer INCLUDED when terminating a token.
19 * Major changes in tokenization routines. Bug fixes in expressions
20 * with lists (fml_sub0).
22 * Revision 1.1.1.1 1995/02/06 13:48:10 adam
23 * First version of the FML interpreter. It's slow and memory isn't
24 * freed properly. In particular, the FML nodes aren't released yet.
35 static char lex_buf[FML_MAX_TOKEN];
37 static void lexer (Fml fml);
39 struct fml_node *fml_group (Fml fml);
41 struct fml_node *fml_tokenize (Fml fml)
45 look_char = (*fml->read_func)();
52 if (look_char != fml->eof_mark)
54 fprintf (stderr, "Ill formed parantheses");
60 void fml_pr_list (struct fml_node *p)
69 fml_atom_str (p->p[0], buf);
75 fml_pr_list (p->p[0]);
82 struct fml_node *fml_group (Fml fml)
84 struct fml_node *ptr0 = NULL, *ptr1, *ptr2;
93 ptr2 = fml_node_alloc (fml);
98 ptr2->p[0] = fml_atom_alloc (fml, lex_buf);
101 else if (look_type == '{')
103 struct fml_node *sptr = fml_group (fml);
106 ptr2 = fml_node_alloc (fml);
116 ptr2 = fml_node_alloc (fml);
132 static void lexer (Fml fml)
137 if (look_char == fml->eof_mark)
142 else if (look_char == fml->comment_char)
145 look_char = (*fml->read_func)();
146 while (look_char != '\n' && look_char != fml->eof_mark);
150 if (!strchr (fml->white_chars, look_char))
152 look_char = (*fml->read_func)();
155 if (look_char == '{')
158 look_char = (*fml->read_func)();
160 else if (look_char == '}')
163 look_char = (*fml->read_func)();
165 else if (look_char == '\'')
168 look_char = (*fml->read_func)();
169 while (look_char != fml->eof_mark && look_char != '\'')
171 lex_buf[off++] = look_char;
172 if (look_char == '\\')
174 look_char = (*fml->read_func)();
178 lex_buf[off-1] = '\n';
181 lex_buf[off-1] = '\n';
184 lex_buf[off-1] = '\'';
187 lex_buf[off-1] = look_char;
190 look_char = (*fml->read_func)();
194 if (look_char == '\'')
195 look_char = (*fml->read_func)();
202 lex_buf[off++] = look_char;
203 look_char = (*fml->read_func)();
204 } while (look_char != fml->eof_mark
205 && !strchr (fml->white_chars, look_char)
206 && look_char != '{' && look_char != '}');
213 if (look_type == 'a')
214 printf ("[%s]", lex_buf);
216 printf ("[%c]", look_type);