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