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