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