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