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