Nodes are freed now. Many bugs fixed.
[egate.git] / fml / fmlp.h
1 /*
2  * FML interpreter. Europagate, 1995
3  *
4  * $Log: fmlp.h,v $
5  * Revision 1.3  1995/02/09 13:07:15  adam
6  * Nodes are freed now. Many bugs fixed.
7  *
8  * Revision 1.2  1995/02/07  16:09:23  adam
9  * The \ character is no longer INCLUDED when terminating a token.
10  * Major changes in tokenization routines. Bug fixes in expressions
11  * with lists (fml_sub0).
12  *
13  * Revision 1.1.1.1  1995/02/06  13:48:10  adam
14  * First version of the FML interpreter. It's slow and memory isn't
15  * freed properly. In particular, the FML nodes aren't released yet.
16  *
17  */
18
19 #include "fml.h"
20
21 #define FML_MAX_TOKEN 2048
22
23 #define FML_ATOM_BUF 12
24
25 struct fml_node {
26     void *p[2];
27     unsigned is_atom : 1;
28 };
29
30 struct fml_atom {
31     struct fml_atom *next;
32     char buf[FML_ATOM_BUF];
33 };
34
35 struct fml_node *fml_tokenize (Fml fml);
36 struct fml_node *fml_node_alloc (Fml fml);
37 struct fml_atom *fml_atom_alloc (Fml fml, char *str);
38 int fml_atom_str (struct fml_atom *a, char *str);
39 void fml_atom_strx (struct fml_atom *a, char *str, int max);
40 int fml_atom_val (struct fml_atom *a);
41 struct fml_node *fml_mk_list (Fml fml, struct fml_node *fn);
42 void fml_node_delete (Fml fml, struct fml_node *fn);
43 struct fml_node *fml_node_copy (Fml fml, struct fml_node *fn);
44
45 struct token {
46     int             kind;
47     int             separate;
48     int             maxbuf;
49     int             offset;
50     char            *atombuf;
51     char            *tokenbuf;
52
53     int             escape_char;
54
55     struct          fml_node *sub;
56     struct          fml_atom *atom;
57     char            sbuf[FML_ATOM_BUF*4];
58 };
59
60 struct fml_sym_info {
61     int kind;
62     struct fml_node *args;
63     struct fml_node *body;
64     struct fml_node *(*binary)(Fml fml, struct fml_node *l,
65                                struct fml_node *r);
66     struct fml_node *(*prefix)(Fml fml, struct fml_node **lp,
67                                struct token *tp);
68 };
69
70 struct fml_sym_tab *fml_sym_open (void);
71 void fml_sym_close (struct fml_sym_tab **tabp);
72 struct fml_sym_info *fml_sym_add (struct fml_sym_tab *tab, const char *s);
73 struct fml_sym_info *fml_sym_add_local (struct fml_sym_tab *tab,const char *s);
74
75 struct fml_sym_info *fml_sym_lookup (struct fml_sym_tab *tab, const char *s);
76 struct fml_sym_info *fml_sym_lookup_local (struct fml_sym_tab *tab,
77                                            const char *s);
78 void fml_sym_push (struct fml_sym_tab *tab);
79 void fml_sym_pop (struct fml_sym_tab *tab, void(*ph)(struct fml_sym_info *i));
80
81 void fml_pr_list (struct fml_node *p);
82 void fml_node_stat (Fml fml);
83
84 #define FML_FUNC     1
85 #define FML_IF       2
86 #define FML_ELSE     3
87 #define FML_PREFIX   4
88 #define FML_VAR      5
89 #define FML_FOREACH  6
90 #define FML_RETURN   7
91 #define FML_SET      8
92 #define FML_WHILE    9
93 #define FML_CBINARY 10
94 #define FML_CPREFIX 11
95 #define FML_BINARY  12
96 #define FML_BIN     13
97
98