From: Adam Dickmeiss Date: Tue, 7 Feb 1995 16:09:23 +0000 (+0000) Subject: The \ character is no longer INCLUDED when terminating a token. X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=db6a18e6dc8f76018718a603fadda55c9b036767;p=egate.git The \ character is no longer INCLUDED when terminating a token. Major changes in tokenization routines. Bug fixes in expressions with lists (fml_sub0). --- diff --git a/fml/fml.c b/fml/fml.c index 2da1b32..5690b56 100644 --- a/fml/fml.c +++ b/fml/fml.c @@ -2,7 +2,12 @@ * 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. @@ -73,7 +78,7 @@ static void pr_indent (int n) { int i = indent; while (--i >= 0) - putchar (' '); + putchar(' '); } if (n > 0) { @@ -234,6 +239,7 @@ static void fml_cmd_lex (struct fml_node **np, struct token *tp) } if (tp->offset == 0) { + tp->separate = 1; if ((*np)->is_atom) { tp->atom = (*np)->p[0]; @@ -261,6 +267,8 @@ static void fml_cmd_lex (struct fml_node **np, struct token *tp) return ; } } + else + tp->separate = 0; cp = tp->atombuf + tp->offset; dst = tp->tokenbuf; if (*cp == tp->escape_char) @@ -293,12 +301,14 @@ static void fml_cmd_lex (struct fml_node **np, struct token *tp) break; } #endif +#if 0 if (tp->kind == 'e') { cp++; if (! *cp) break; } +#endif tp->offset = cp - tp->atombuf; tp->after_char = '\0'; return ; @@ -516,6 +526,7 @@ static struct fml_node *fml_exec_ge (Fml fml, struct fml_node *l, static struct fml_node *fml_exec_space (Fml fml, struct fml_node **lp, struct token *tp) { + putchar ('_'); return NULL; } @@ -769,7 +780,7 @@ static struct fml_node *fml_sub1 (Fml fml, struct fml_node **lp, } #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; @@ -794,23 +805,40 @@ static struct fml_node *fml_sub_bad (Fml fml, struct fml_node *list) 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, @@ -984,7 +1012,7 @@ static struct fml_node *fml_exec_group (struct fml_node *list, Fml fml) { struct token token; struct fml_sym_info *info; - int separate = 0; + int first = 1; struct fml_node *return_value = NULL, *rv; if (!list) @@ -1077,12 +1105,11 @@ static struct fml_node *fml_exec_group (struct fml_node *list, Fml fml) 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: @@ -1094,7 +1121,7 @@ static struct fml_node *fml_exec_group (struct fml_node *list, Fml fml) 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; @@ -1127,19 +1154,14 @@ static struct fml_node *fml_exec_group (struct fml_node *list, Fml fml) } break; case 't': - if (separate) +#if 0 + printf ("", 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); } diff --git a/fml/fmlp.h b/fml/fmlp.h index 5b0aa34..5431986 100644 --- a/fml/fmlp.h +++ b/fml/fmlp.h @@ -2,8 +2,14 @@ * FML interpreter. Europagate, 1995 * * $Log: fmlp.h,v $ - * Revision 1.1 1995/02/06 13:48:09 adam - * Initial revision + * Revision 1.2 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.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. * */ @@ -35,6 +41,7 @@ struct fml_node *fml_node_copy (Fml fml, struct fml_node *fn); struct token { int kind; + int separate; int after_char; int maxbuf; int offset; diff --git a/fml/fmltest.c b/fml/fmltest.c index 24158d3..1947ba2 100644 --- a/fml/fmltest.c +++ b/fml/fmltest.c @@ -2,25 +2,65 @@ * 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 #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; } diff --git a/fml/fmltoken.c b/fml/fmltoken.c index 3e7793a..77f9139 100644 --- a/fml/fmltoken.c +++ b/fml/fmltoken.c @@ -2,8 +2,14 @@ * 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 @@ -79,6 +85,18 @@ struct fml_node *fml_group (Fml fml) { 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); @@ -88,7 +106,7 @@ struct fml_node *fml_group (Fml fml) ptr1->p[1] = ptr2; ptr2->p[0] = sptr; ptr2->is_atom = 0; - } + } else { ptr2 = sptr; @@ -97,6 +115,8 @@ struct fml_node *fml_group (Fml fml) else ptr1->p[1] = ptr2; } +#endif + } else { ptr2 = fml_node_alloc (fml); diff --git a/fml/lists.fml b/fml/lists.fml new file mode 100644 index 0000000..346628a --- /dev/null +++ b/fml/lists.fml @@ -0,0 +1,17 @@ +# FML list inspection +# +# $Id: lists.fml,v 1.1 1995/02/07 16:09:24 adam Exp $ +\set months {Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec} +\set days {31 28 31 30 31 30 31 31 30 31 30 31} +\foreach m \months + {Month: \m\n} +\set i 1 +Number of days in every month:\n +\while {\i \le 12} +{ + \months \index \i : \ \days \index \i + \if {\i \eq 6} {\n} \else {,\ } + \incr \i +} +\n +\foreach ost { {feta ost} brie danbo } { \ost\ }