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