* FML interpreter. Europagate, 1995
*
* $Log: fml.c,v $
- * Revision 1.2 1995/02/06 15:23:25 adam
+ * Revision 1.3 1995/02/07 16:09:23 adam
+ * The \ character is no longer INCLUDED when terminating a token.
+ * Major changes in tokenization routines. Bug fixes in expressions
+ * with lists (fml_sub0).
+ *
+ * Revision 1.2 1995/02/06 15:23:25 adam
* Added some more relational operators (le,ne,ge). Added increment
* and decrement operators. Function index changed, so that first
* element is 1 - not 0. Function fml_atom_val edited.
{
int i = indent;
while (--i >= 0)
- putchar (' ');
+ putchar(' ');
}
if (n > 0)
{
}
if (tp->offset == 0)
{
+ tp->separate = 1;
if ((*np)->is_atom)
{
tp->atom = (*np)->p[0];
return ;
}
}
+ else
+ tp->separate = 0;
cp = tp->atombuf + tp->offset;
dst = tp->tokenbuf;
if (*cp == tp->escape_char)
break;
}
#endif
+#if 0
if (tp->kind == 'e')
{
cp++;
if (! *cp)
break;
}
+#endif
tp->offset = cp - tp->atombuf;
tp->after_char = '\0';
return ;
static struct fml_node *fml_exec_space (Fml fml, struct fml_node **lp,
struct token *tp)
{
+ putchar ('_');
return NULL;
}
}
#if 0
-static struct fml_node *fml_sub_bad (Fml fml, struct fml_node *list)
+static struct fml_node *fml_sub0 (Fml fml, struct fml_node *list)
{
struct token token;
struct fml_node *fn, *fn1;
fml_del_token (&token, fml);
return fn;
}
-#endif
-
+#else
static struct fml_node *fml_sub0 (Fml fml, struct fml_node *list)
{
struct token token;
- struct fml_node *fn, *fn1;
+ struct fml_node *fn, *fn0, *fn1;
fml_init_token (&token, fml);
assert (list);
fml_cmd_lex (&list, &token);
fn1 = fn = fml_sub1 (fml, &list, &token);
-
+ if (fn->p[1] && token.kind != '\0')
+ {
+ fn1 = fml_node_alloc (fml);
+ fn1->p[0] = fn;
+ }
+ fn0 = fn1;
while (token.kind != '\0')
- fn1 = fn1->p[1] = fml_sub1 (fml, &list, &token);
+ {
+ fn = fml_sub1 (fml, &list, &token);
+ if (fn->p[1])
+ {
+ fn1 = fn1->p[1] = fml_node_alloc (fml);
+ fn1->p[0] = fn;
+ }
+ else
+ {
+ fn1 = fn1->p[1] = fn;
+ }
+ }
fml_del_token (&token, fml);
- return fn;
+ return fn0;
}
+#endif
+
static struct fml_node *fml_exec_foreach (struct fml_sym_info *info, Fml fml,
struct fml_node **lp,
{
struct token token;
struct fml_sym_info *info;
- int separate = 0;
+ int first = 1;
struct fml_node *return_value = NULL, *rv;
if (!list)
case FML_VAR:
case FML_PREFIX:
case FML_CPREFIX:
- if (separate)
+ if (token.separate && !first)
+ {
putchar (' ');
- if (token.offset == 0)
- separate = ' ';
- else
- separate = 0;
+ }
+ first = 1;
fml_emit_expr (fml, &list, &token);
continue;
case FML_FOREACH:
rv = fml_exec_if (info, fml, &list, &token);
if (rv)
return_value = rv;
- break;
+ continue;
case FML_SET:
fml_exec_set (info, fml, &list, &token);
break;
}
break;
case 't':
- if (separate)
+#if 0
+ printf ("<token.tokenbuf=%s>", token.tokenbuf);
+#endif
+ if (token.separate && !first)
putchar (' ');
- if (token.offset == 0)
- separate = ' ';
- else
- separate = 0;
+ first = 0;
fml_emit_expr (fml, &list, &token);
continue;
-#if 0
- printf ("%s", token.tokenbuf);
- if (token.after_char)
- putchar (token.after_char);
-#endif
}
fml_cmd_lex (&list, &token);
}
* FML interpreter. Europagate, 1995
*
* $Log: fmltest.c,v $
- * Revision 1.1 1995/02/06 13:48:09 adam
- * Initial revision
+ * Revision 1.2 1995/02/07 16:09:24 adam
+ * The \ character is no longer INCLUDED when terminating a token.
+ * Major changes in tokenization routines. Bug fixes in expressions
+ * with lists (fml_sub0).
+ *
+ * Revision 1.1.1.1 1995/02/06 13:48:10 adam
+ * First version of the FML interpreter. It's slow and memory isn't
+ * freed properly. In particular, the FML nodes aren't released yet.
*
*/
#include <stdio.h>
#include "fml.h"
+static FILE *inf;
+
+static int inf_read (void)
+{
+ return getc (inf);
+}
+
int main (int argc, char **argv)
{
Fml fml;
+ int nfiles = 0;
fml = fml_open ();
- if (argc >= 2 && (!strcmp (argv[1], "d") ||
- !strcmp (argv[1], "debug")))
+ while (-- argc > 0)
+ {
+ ++argv;
+ if (**argv == '-')
+ {
+ if (argv[0][1] == 'd')
+ fml->debug = 1;
+ else
+ {
+ fprintf (stderr, "uknown option `%s'\n", *argv);
+ exit (1);
+ }
+ }
+ else
+ {
+ nfiles++;
+ inf = fopen (*argv, "r");
+ if (!inf)
+ {
+ fprintf (stderr, "cannot open `%s'\n", *argv);
+ exit (1);
+ }
+ fml->read_func = inf_read;
+ fml_preprocess (fml);
+ fml_exec (fml);
+ fclose (inf);
+ }
+ }
+ if (!nfiles)
{
- fml->debug = 1;
+ fml_preprocess (fml);
+ fml_exec (fml);
}
- fml_preprocess (fml);
- fml_exec (fml);
return 0;
}
* FML interpreter. Europagate, 1995
*
* $Log: fmltoken.c,v $
- * Revision 1.1 1995/02/06 13:48:09 adam
- * Initial revision
+ * Revision 1.2 1995/02/07 16:09:24 adam
+ * The \ character is no longer INCLUDED when terminating a token.
+ * Major changes in tokenization routines. Bug fixes in expressions
+ * with lists (fml_sub0).
+ *
+ * Revision 1.1.1.1 1995/02/06 13:48:10 adam
+ * First version of the FML interpreter. It's slow and memory isn't
+ * freed properly. In particular, the FML nodes aren't released yet.
*
*/
#include <string.h>
{
struct fml_node *sptr = fml_group (fml);
if (sptr)
+ {
+#if 1
+ ptr2 = fml_node_alloc (fml);
+ if (!ptr0)
+ ptr0 = ptr2;
+ else
+ ptr1->p[1] = ptr2;
+ ptr2->p[0] = sptr;
+ ptr2->is_atom = 0;
+
+#else
+/* make group of one become an element ... */
if (sptr->p[1])
{
ptr2 = fml_node_alloc (fml);
ptr1->p[1] = ptr2;
ptr2->p[0] = sptr;
ptr2->is_atom = 0;
- }
+ }
else
{
ptr2 = sptr;
else
ptr1->p[1] = ptr2;
}
+#endif
+ }
else
{
ptr2 = fml_node_alloc (fml);