git @ Cat's Eye Technologies OpenZz / b6f43ff
Reduce warnings (#2) * Begin reducing the number of compiler warnings. * Checkpoint reducing the compiler warnings. * Eliminate yet more compiler warnings. Still so many to go. * The continuing quest for no compiler warnings * More prototypes in kernel.h, for the macros. * More warnings, more worrisome signature mismatches * Checkpoint * No warnings in param.c or parse.c anymore. * Checkpoint * Eliminate compiler warnings in rule.c and scope.c. * Address some warnings in sys.c. * Continue cleaning up sys.c. * Address compiler warnings in zlex.c. * Elminate compiler warnings in table.c. * Reduce warnings in zsys.c. * Reduce warnings further in sys.c. * Eliminate warnings in zsys.c. Chris Pressey authored 1 year, 10 months ago GitHub committed 1 year, 10 months ago
23 changed file(s) with 448 addition(s) and 466 deletion(s). Raw diff Collapse all Expand all
2727 #include "param.h"
2828 #include "trace.h"
2929
30 /*PROTOTYPES*/
31 int parse(struct s_nt *);
32 void pop_source(void);
33 int source_list(struct s_content *, void *);
34
3035 struct s_content zz_ret_value = {0,0};
3136
3237 /*--------------------------------------------------------------------------*/
4045
4146 #define MAX_ARGV 100
4247
43 action(rule,stack,ret)
44 struct s_rule *rule;
45 struct s_content stack[],*ret;
48 void action(struct s_rule *rule, struct s_content stack[], struct s_content *ret)
4649 {
4750 struct s_content cnt,old_zz_ret_value;
4851 struct s_content argv [MAX_ARGV]; /* allocation issue */
197200 push_param_scope();
198201 for(i=0;i<argc;i++)
199202 set_param(namev[i],&argv[i]);
200 source_list(&rule->action);
203 source_list(&rule->action, NULL);
201204 if(!root_nt) root_nt=find_nt("root");
202205 if(zz_trace_mask()&TRACE_ZZACTION)
203206 {
288291
289292 }
290293
291 fprint_action(action)
294 void fprint_action(action)
292295 struct content *action;
293296 {
294297
1818
1919
2020 #include <stdint.h>
21 #include <string.h>
22
2123 #include "zlex.h"
2224 #include "rule.h"
2325 #include "avl.h"
2426 #include "err.h"
27 #include "printz.h"
28
29 /*PROTOTYPES*/
30 int do_dumpnet(struct s_nt *);
2531
2632 static struct s_dot *hd_dot=0;
2733
3541
3642 /*----------------------------------------------------------------------------*/
3743
38 static dump_tran(string)
39 char *string;
44 static void dump_tran(char *string)
4045 {
4146 int i,tab;
4247 char buffer[256];
150155
151156 /*----------------------------------------------------------------------------*/
152157
153 static dump_rule(rule)
154 struct s_rule *rule;
158 static void dump_rule(struct s_rule *rule)
155159 {
156160 char buffer[256];
157161 printz(buffer,"reduce: %r", rule);
160164
161165 /*----------------------------------------------------------------------------*/
162166
163 dumpnet(ntname)
164 char *ntname;
167 void dumpnet(char *ntname)
165168 {
166169 int i;
167170 struct s_nt *nt;
177180
178181 /*----------------------------------------------------------------------------*/
179182
180 do_dumpnet(nt)
181 struct s_nt *nt;
183 int do_dumpnet(struct s_nt *nt)
182184 {
183185 int i;
184186 struct s_dot *dot;
2929
3030 #include <stdio.h>
3131 #include <stdint.h>
32 #include <stdlib.h>
3233 #include "err.h"
3334 #include "zlex.h"
3435 #include "printz.h"
4041 #else
4142 #include <varargs.h>
4243 #endif
44
45 /*PROTOTYPES*/
46 void get_source_file(char *);
47 void error_head(int);
48 void error_tail(void);
49 void error_tail_1(void);
50 void change_filetype(char *fullfilename,char *filetype);
51 void fprint_source_position(FILE *,int);
52 void fprint_param(FILE *);
53 int do_printz(FILE *chanout, FILE *chanout_1,
54 char *stringout, char *fmt, va_list *ap);
55 void check_error_max_number(void);
4356
4457 char err_file[256] = "LOG.ERR";
4558
5972
6073 /*---------------------------------------------------------------------------*/
6174
62 open_err_file()
75 void open_err_file(void)
6376 {
6477 char filename[132];
6578 static int err_file_flag=0;
180193
181194 /*---------------------------------------------------------------------------*/
182195
183 error_head(type)
196 void error_head(type)
184197 int type;
185198 {
186199 open_err_file();
234247
235248 /*---------------------------------------------------------------------------*/
236249
237 error_tail()
250 void error_tail(void)
238251 {
239252 fprintz(stderr," ****\n");
240253 if(err_chan) fprintz(err_chan," ****\n");
251264
252265 /*---------------------------------------------------------------------------*/
253266
254 error_tail_1()
267 void error_tail_1(void)
255268 {
256269 fprintz(stderr," ****\n");
257270 if(err_chan) fprintz(err_chan," ****\n");
268281
269282 /*---------------------------------------------------------------------------*/
270283
271 error_token(cnt)
272 struct s_content *cnt;
284 void error_token(struct s_content *cnt)
273285 {
274286 fprintz(stderr,"%z ",cnt);
275287 if(err_chan) fprintz(err_chan,"%z ",cnt);
279291 /*---------------------------------------------------------------------------*/
280292
281293
282 print_error_count()
294 void print_error_count(void)
283295 {
284296 if(total_error_n)
285297 {
298310 /*---------------------------------------------------------------------------*/
299311
300312
301 get_error_number()
313 int get_error_number(void)
302314 {
303315 return lexical_error_n+error_n+fatal_error_n+unknown_error_n+internal_error_n;
304316 }
305317
306318 /*---------------------------------------------------------------------------*/
307319
308 syntax_error(info_routine)
309 int (*info_routine)();
320 void syntax_error(int (*info_routine)())
310321 {
311322 open_err_file();
312323 fprintz(stderr,"+ **** SYNTAX ERROR ****\n");
327338
328339 /*---------------------------------------------------------------------------*/
329340
330 check_error_max_number()
341 void check_error_max_number(void)
331342 {
332343 static int count=0;
333344 char *s;
343354 }
344355 }
345356
346 set_max_error_n(argc,argv,ret)
347 int argc;
348 struct s_content argv[],*ret;
357 int set_max_error_n(int argc, struct s_content argv[], struct s_content *ret)
349358 {
350359 int n;
351 if(argc!=1) return;
360 if(argc!=1) return -1;
352361 n=(int)s_content_value(argv[0]);
353362 max_error_n=n;
363 return 0;
354364 }
355365
356366 int zz_get_error_number()
2424
2525 #include <stdint.h>
2626 #include "zlex.h"
27 #include "rule.h"
28
29 /*PROTOTYPES*/
30 void open_rule(char *);
31 void setaction_exeproc(int (*proc)(), struct s_tag *tag);
32 void setaction_exesproc(int (*sproc)(), struct s_tag *tag);
33 void setaction_pass(void);
34 void insert_rule(char *, struct s_rule *);
35 void init_zlex(void);
36 void append_t_bead(struct s_content *cnt);
37 void append_nt_bead(char *ntname, char *beadname);
2738
2839 /*-------------------------------------------------------------------------*/
2940
30 zz_bind_open(s)
31 const char *s;
41 int zz_bind_open(const char *s)
3242 {
3343 if(!init_zlex_done)
3444 init_zlex();
3848
3949 /*-------------------------------------------------------------------------*/
4050
41 zz_bind_match(s)
42 const char *s;
51 int zz_bind_match(const char *s)
4352 {
4453 append_nt_bead(zlex_strsave(s),0);
4554 return 1;
4756
4857 /*-------------------------------------------------------------------------*/
4958
50 zz_bind_keyword(s)
51 const char *s;
59 int zz_bind_keyword(const char *s)
5260 {
5361 struct s_content cnt;
5462 cnt.tag=tag_qstring;
5967
6068 /*-------------------------------------------------------------------------*/
6169
62 zz_bind_close()
70 int zz_bind_close(void)
6371 {
6472 insert_rule(0,close_rule());
6573 return 1;
6775
6876 /*-------------------------------------------------------------------------*/
6977
70 zz_bind_call(proc)
71 int (*proc)();
78 int zz_bind_call(int (*proc)())
7279 {
7380 setaction_exesproc(proc,tag_none);
7481 return 1;
7683
7784 /*-------------------------------------------------------------------------*/
7885
79 zz_bind_call_fun(proc,tag)
80 int (*proc)();
81 const char *tag;
86 int zz_bind_call_fun(int (*proc)(), const char *tag)
8287 {
8388 setaction_exesproc(proc,find_tag(tag));
8489 return 1;
8691
8792 /*-------------------------------------------------------------------------*/
8893
89 zz_bind_call_fun_tag(proc,tag)
90 int (*proc)();
91 struct s_tag *tag;
94 int zz_bind_call_fun_tag(int (*proc)(), struct s_tag *tag)
9295 {
9396 setaction_exesproc(proc,tag);
9497 return 1;
9699
97100 /*-------------------------------------------------------------------------*/
98101
99 zz_bind_call_exe_proc(proc,tag)
100 int (*proc)();
101 const char *tag;
102 int zz_bind_call_exe_proc(int (*proc)(), const char *tag)
102103 {
103104 setaction_exeproc(proc,find_tag(tag));
104105 return 1;
106107
107108 /*-------------------------------------------------------------------------*/
108109
109 zz_bind_call_exe_no_tag(proc)
110 int (*proc)();
110 int zz_bind_call_exe_no_tag(int (*proc)())
111111 {
112112 setaction_exeproc(proc,0);
113113 return 1;
115115
116116 /*-------------------------------------------------------------------------*/
117117
118 zz_bind_pass()
118 int zz_bind_pass(void)
119119 {
120120 setaction_pass();
121121 return 1;
2323 #include "sys.h"
2424
2525
26 kernel()
26 void kernel(void)
2727 {
2828 struct s_tag *tag;
2929 extern int max_error_n;
1818
1919 #ifndef __KERNEL_H__
2020 #define __KERNEL_H__
21
22 /*PROTOTYPES*/
23 void init_zlex(void);
24 void setaction_exesproc(int (*sproc)(), struct s_tag *tag);
25 void setaction_exeproc(int (*proc)(), struct s_tag *tag);
26 void setaction_pass(void);
27 void setaction_merge();
28 void setaction_merge_all();
29 void setaction_list();
30 void setaction_append();
31 void setaction_return(struct s_content *, char *);
32 void insert_rule(); /* actual signature is: void insert_rule(char *, struct s_rule *); */
33 void append_t_bead(struct s_content *);
34 void append_nt_bead(char *, char *);
35 void set_recovery(char *, char *);
36 void set_nt_prompt(char *, const char *);
37 void open_rule(char *);
38 struct s_rule *close_rule(void);
2139
2240 #define OPEN(S) {INIT_ZLEX open_rule(zlex_strsave( #S ));}
2341 #define GSB(S) append_nt_bead(zlex_strsave( #S),0);
1717 */
1818
1919 #include <stdint.h>
20 #include <stdlib.h>
21 #include <string.h>
22
2023 #include "rule.h"
2124
2225
7780 /*----------------------------------------------------------------*/
7881
7982
80 lazy_rec(dots,len)
83 void lazy_rec(dots,len)
8184 struct s_dot *dots[];
8285 int len;
8386 {
9497 /*----------------------------------------------------------------*/
9598
9699
97 print_lazy_report()
100 int print_lazy_report()
98101 {
99102 struct s_l_node *node;
100103 int k,i,count,flag;
124127 node=node->next;
125128 }
126129 }
130 return 0;
127131 }
128132 static char sccsid[]="@(#)lazy.c 6.1\t9/7/94";
129133 static char rcsid[] = "$Id: lazy.c,v 1.3 2002/01/11 11:52:02 brooks Exp $ ";
2929
3030 #include <stdio.h>
3131 #include <stdint.h>
32 #include <stdlib.h>
33 #include <string.h>
34
3235 #include "zlex.h"
3336 #include "list.h"
3437 #include "mem.h"
1717 */
1818
1919 #include <stdint.h>
20 #include <stdlib.h>
21 #include <string.h>
22
2023 #include "zlex.h"
2124 #include "rule.h"
2225 #include "err.h"
6366
6467 /*------------------------------------------------------------------------*/
6568
66 static free_param_pair(pair)
67 struct s_param_pair *pair;
69 static void free_param_pair(struct s_param_pair *pair)
6870 {
6971 pair->next=param_first_free;
7072 pair->name=0;
7476
7577 /*------------------------------------------------------------------------*/
7678
77 push_param_scope()
79 int push_param_scope(void)
7880 {
7981 if(param_level>=PARAM_SCOPE_STACK_SIZE-1)
8082 zz_error(ERROR,"too many Zz variable scopes");
8284 {
8385 param_scope_stack[param_level++] = 0;
8486 }
85 }
86
87 /*------------------------------------------------------------------------*/
88
89 pop_param_scope()
87 return 0;
88 }
89
90 /*------------------------------------------------------------------------*/
91
92 int pop_param_scope(void)
9093 {
9194 struct s_param_pair *pair,*tmp;
9295 if(param_level>0)
102105 free_param_pair(tmp);
103106 }
104107 }
108 return 0;
105109 }
106110
107111 /*------------------------------------------------------------------------*/
151155
152156 /*------------------------------------------------------------------------*/
153157
154 gset_param(char *name, struct s_content *cnt)
158 int gset_param(char *name, struct s_content *cnt)
155159 {
156160 struct s_param_pair *pair;
157161 struct s_content *old;
183187
184188 /*------------------------------------------------------------------------*/
185189
186 gnset_param(name,cnt,delta)
190 int gnset_param(name,cnt,delta)
187191 char *name;
188192 struct s_content *cnt;
189193 int delta;
222226
223227 /*------------------------------------------------------------------------*/
224228
225 unset_param(name)
226 char *name;
229 int unset_param(char *name)
227230 {
228231 struct s_param_pair *pair,**ptr;
229232 struct s_content *old;
230233 int i;
231234 if(strcmp(name,"$")==0) return 1;
232235 i=param_level-1;
233 if(i<0) return;
236 if(i<0) return 0;
234237 ptr= &(param_scope_stack[i]);
235238 while(*ptr && (*ptr)->name!=name) ptr= &((*ptr)->next);
236239 if(*ptr)
241244 (*pair->cnt.tag->param_off)(&(pair->cnt),pair->name);
242245 free_param_pair(pair);
243246 }
247 return 0;
244248 }
245249
246250
254258 returns 1 if local param found
255259 returns 2 if global param found
256260 */
257 param_substitute(token,paramname)
258 struct s_content *token;
259 char **paramname;
261 int param_substitute(struct s_content *token, char **paramname)
260262 {
261263 struct s_param_pair *pair;
262264 struct s_content *cnt;
284286
285287 /*------------------------------------------------------------------------*/
286288
287 local_param_substitute(token,paramname)
288 struct s_content *token;
289 struct s_content *paramname;
289 int local_param_substitute(struct s_content *token, struct s_content *paramname)
290290 {
291291 struct s_param_pair *pair;
292292 struct s_content *cnt;
293293 char *name;
294294 int i;
295295 paramname->tag = tag_none;
296 if(token->tag!=tag_ident) return;
296 if(token->tag!=tag_ident) return 0;
297297 name = (char*)s_content_value(*token);
298298 if(param_level>0)
299299 {
306306 s_content_value(*paramname) = (long)name; /*ep*/
307307 cnt = &(pair->cnt);
308308 *token = *cnt;
309 return;
310309 }
311310 }
312 }
313
314 /*------------------------------------------------------------------------*/
315
316 s_param_filter(argc,argv,ret)
317 int argc;
318 struct s_content argv[],*ret;
311 return 0;
312 }
313
314 /*------------------------------------------------------------------------*/
315
316 int s_param_filter(int argc, struct s_content argv[], struct s_content *ret)
319317 {
320318 struct s_param_pair *pair;
321319 int i,lev;
339337 /*------------------------------------------------------------------------*/
340338
341339
342 list_params()
340 int list_params(void)
343341 {
344342 struct s_param_pair *pair;
345343 int i,lev;
371369
372370 /*---------------------------------------------------------------------------*/
373371
374 show_param_memory()
372 int show_param_memory(void)
375373 {
376374 PRINTMEM("param",param_mem)
375 return 0;
377376 }
378377
379378
1818
1919 #include <stdio.h>
2020 #include <stdint.h>
21 #include <stdlib.h>
22 #include <string.h>
23
2124 #include "zz.h"
2225 #include "zlex.h"
2326 #include "rule.h"
2528 #include "avl.h"
2629 #include "trace.h"
2730
31 /*PROTOTYPES*/
32 int next_token(struct s_content *);
33 void syntax_error(int (*info_routine)());
34 void action(struct s_rule *rule, struct s_content stack[], struct s_content *ret);
35 int get_error_number(void);
36 int errprintf(char *fmt,...);
37 int param_substitute(struct s_content *token,char **paramname);
38 /*FORWARD*/
39 int check_reduce(int, struct s_rule *);
40 void lr_reduce(struct s_rule *, int, struct s_content *);
41 void dump_stack(void);
2842
2943 /*---------------------------------------------------------------------------*/
3044
3145 extern struct s_nt *nt_any,*nt_param,*nt_gparam;
32 static char *first_prompt="";
33 static max_dot=0,tot_dot=0,ndot=0,max_sp=0;
46 static const char *first_prompt="";
47 static int max_dot=0,tot_dot=0,ndot=0,max_sp=0;
3448 static int reduction_count=0;
3549 #define EXPECTED_SIZE 30
3650 static struct s_content expected[EXPECTED_SIZE];
178192 static long int setid=0;
179193
180194 /* calcola la chiusura del work set */
181 make_closure()
195 void make_closure(void)
182196 {
183197 void lr_add_nt();
184198 int i,a=cur_lrenv.a,b=cur_lrenv.b;
221235
222236 */
223237
224 try_shift(set_index)
225 int set_index;
238 void try_shift(int set_index)
226239 {
227240 struct s_term_tran *ttran;
228241 struct s_nt_tran *nttran;
288301 /*----------------------------------------------------------------------*/
289302
290303 /* ritorna 1 se lo shift e' ammissibile */
291 check_shift(set_index)
292 int set_index;
304 int check_shift(int set_index)
293305 {
294306 struct s_term_tran *ttran;
295307 struct s_nt_tran *nttran;
319331
320332 */
321333
322 try_reduce(set_index,rule)
323 int set_index;
324 struct s_rule *rule;
334 int try_reduce(int set_index, struct s_rule *rule)
325335 {
326336 LRENV oldenv;
327337 int oldset,i,j,k,a,b,curset,ret,length,base;
383393
384394 /*----------------------------------------------------------------------*/
385395
386 check_reduce(set_index,rule)
387 int set_index;
388 struct s_rule *rule;
396 int check_reduce(int set_index, struct s_rule *rule)
389397 {
390398 int oldset,i,j,k,a,b,curset,ret,length,base;
391399 struct s_nt *nt;
434442 /*----------------------------------------------------------------------*/
435443
436444
437 lr_loop(main_nt)
438 struct s_nt *main_nt;
445 int lr_loop(struct s_nt *main_nt)
439446 {
440447 struct s_content ret_token,shift_token;
441448 int i,j,dst,a,b,newa,newb,olda,oldb,is_param;
552559
553560 /*----------------------------------------------------------------------*/
554561
555 lr_reduce(rule,set_index,ret_token)
556 struct s_rule *rule;
557 int set_index;
558 struct s_content *ret_token;
562 void lr_reduce(struct s_rule *rule, int set_index, struct s_content *ret_token)
559563 {
560564 int i,length;
561565 reduction_count++;
577581
578582 /*----------------------------------------------------------------------*/
579583
580 static add_expected(tag,value)
584 static int add_expected(tag,value)
581585 struct s_tag *tag;
582586 long value;
583587 {
607611
608612 /*----------------------------------------------------------------------*/
609613
610 static compute_expected_from_reduction(set_index,rule)
614 static int compute_expected_from_reduction(set_index,rule)
611615 int set_index;
612616 struct s_rule *rule;
613617 {
674678
675679 /*----------------------------------------------------------------------*/
676680
677 static void print_expected()
681 static int print_expected()
678682 {
679683 char buffer[256];
680684 int i,j,k;
707711
708712 if(j>0) errprintf("| %s\n",buffer);
709713 }
710 }
711
712 /*----------------------------------------------------------------------*/
713
714 recovery()
714 return 0;
715 }
716
717 /*----------------------------------------------------------------------*/
718
719 int recovery(void)
715720 {
716721 struct {struct s_content cnt; struct s_nt *nt;int lrset;}
717722 tmpterm,termlist[1000];
820825 Associa una lista di termini di recovery ad un non-terminale
821826
822827 */
823 set_recovery(ntname,termlist)
824 char *ntname,*termlist;
828 void set_recovery(char *ntname, char *termlist)
825829 {
826830 struct s_nt *nt;
827831 int i;
888892
889893 */
890894
891 set_nt_prompt(ntname,prompt)
892 char *ntname,*prompt;
895 void set_nt_prompt(char *ntname, const char *prompt)
893896 {
894897 struct s_nt *nt;
895898 if(ntname)
905908 /*----------------------------------------------------------------------*/
906909
907910
908 dump_dot(dot,off)
909 struct s_dot *dot;
910 int off;
911 void dump_dot(struct s_dot *dot, int off)
911912 {
912913 int length;
913914 struct s_term_tran *ttran;
929930
930931 /*----------------------------------------------------------------------*/
931932
932 dump_stack()
933 void dump_stack(void)
933934 {
934935 #define IMAGE_SIZE 10
935936 int image[IMAGE_SIZE],image_n;
957958
958959 /*----------------------------------------------------------------------*/
959960
960 dump_set(set_index)
961 int set_index;
961 void dump_set(int set_index)
962962 {
963963 int i,a,b;
964964 a=lrstack[set_index].a;
974974
975975 /*----------------------------------------------------------------------*/
976976
977 write_dot_stat()
977 void write_dot_stat(void)
978978 {
979979 printf("dot n.: max=%d, mean=%d\n",max_dot,ndot==0?0:tot_dot/ndot);
980980 printf("lr sp: max=%d\n",max_sp);
982982
983983 /*------------------------------------------------------------------*/
984984
985 print_report()
985 void print_report(void)
986986 {
987987 static int old_reduction_count=0;
988988 printf("%d reductions done (%+d)\n",
993993
994994 /*------------------------------------------------------------------*/
995995
996 fprint_param(chan)
996 void fprint_param(chan)
997997 FILE *chan;
998998 {
999999 if(cur_token.is_param)
10071007
10081008 /*------------------------------------------------------------------*/
10091009
1010 parse(start_nt)
1011 struct s_nt *start_nt;
1010 int parse(struct s_nt *start_nt)
10121011 {
10131012 int ret;
10141013 struct s_cur_token old_token;
10351034 if(ret>0) break;
10361035 if(ret==0) syntax_error(print_expected);
10371036 if(!recovery())
1038 {
1039 zz_error(FATAL_ERROR,"unrecoverable error");
1040 break;
1041 }
1037 {
1038 zz_error(FATAL_ERROR,"unrecoverable error");
1039 break;
1040 }
10421041 }
10431042
10441043 cur_lrenv = old_lrenv;
5656
5757 #include <stdio.h>
5858 #include <stdint.h>
59 #include <stdlib.h>
60 #include <string.h>
61
5962 #include "avl.h"
6063 #include "rule.h"
6164 #include "list.h"
6568 #include "table.h"
6669 #include "printz.h"
6770
71 /*PROTOTYPES*/
72 int param_substitute(); /* signature int param_substitute(struct s_content *token,char **paramname) in param.h is incompatible */
73 int parse(struct s_nt *);
74 int source_list(); /* signature int source_list(struct s_content *, void *); is incompatible */
75 void pop_source(void);
76
6877 static int nt_mem=0;
6978 static int rule_mem=0;
7079 struct s_nt *nt_any=0,*nt_param=0,*nt_gparam;
174183 ntname = (char*)s_content_value(tmp1);
175184 if(!init_rule_done) init_rule();
176185 if(cur_rule)
177 free_rule(cur_rule);
186 free_rule(cur_rule, NULL);
178187 cur_rule = (struct s_rule *)calloc(1,sizeof(struct s_rule));
179188 rule_mem += sizeof(struct s_rule);
180189 cur_rule->bead_n=1;
520529 }
521530 }
522531
523 void free_rule(void *_rule /*, void *dummy_param*/)
532 void free_rule(void *_rule, void *dummy_param)
524533 {
525534 struct s_rule *rule = (struct s_rule *)_rule;
526535 do_delete_scope_action(rule);
4747
4848 struct s_nt {
4949 char *name;
50 char *prompt;
50 const char *prompt;
5151 struct s_dot *first_dot;
5252 };
5353
8181 struct s_nt
8282 *find_nt();
8383
84 void free_rule(void * rule_param/*, void* dummy_param*/);
84 void open_rule(char *);
85 void free_rule(void *, void *);
8586 void init_rule();
8687 struct s_rule *close_rule();
8788 struct s_dot *find_nt_tran(),*find_term_tran();
2020
2121 #include <stdio.h>
2222 #include <stdint.h>
23 #include <stdlib.h>
24 #include <string.h>
25
2326 #include "zz.h"
2427 #include "avl.h"
2528 #include "rule.h"
2730 #include "err.h"
2831 #include "trace.h"
2932
33 /*PROTOTYPES*/
34 int parse(struct s_nt *);
35 void pop_source(void);
36 int source_list(struct s_content *, void *);
37 /*FORWARD*/
38 void delete_scope(char *name);
39 void do_list_rules(char *sintname, int kflag);
40
3041 struct s_scope {
3142 char enabled;
32 char *name;
33 TREE *rules;
43 char *name;
44 TREE *rules;
3445 struct s_scope *previous,*next;
35 };
36
37
46 };
47
3848 static struct s_scope *top_scope=0,*cur_scope=0;
3949 static TREE *scope_tree=0;
4050 static int link_flag=0;
7787
7888 /*---------------------------------------------------------------------------*/
7989
80 zz_push_scope(scope_name)
81 char *scope_name;
90 void zz_push_scope(char *scope_name)
8291 {
8392 struct s_scope *scope,*new_scope;
8493 new_scope = find_scope(scope_name);
95104 }
96105
97106 /*---------------------------------------------------------------------------*/
98 delete_and_push_scope(scope_name)
99 char *scope_name;
107 int delete_and_push_scope(char *scope_name)
100108 {
101109 delete_scope(scope_name);
102 zz_push_scope(scope_name);
103 }
104
105 /*---------------------------------------------------------------------------*/
106
107 zz_pop_scope()
110 zz_push_scope(scope_name);
111 return 0;
112 }
113
114 /*---------------------------------------------------------------------------*/
115
116 void zz_pop_scope(void)
108117 {
109118 struct s_scope *scope;
110119 if(!top_scope || !top_scope->previous)
212221
213222 /*---------------------------------------------------------------------------*/
214223
215 insert_rule(scope_name,rule)
216 char *scope_name;
217 struct s_rule *rule;
224 void insert_rule(char *scope_name, struct s_rule *rule)
218225 {
219226 struct s_scope *scope,*dst_scope;
220227 struct s_rule *oldrule,*r;
237244
238245 if(oldrule->when_change_action.tag==tag_list)
239246 {
240 source_list(&oldrule->when_change_action);
247 source_list(&oldrule->when_change_action, NULL);
241248 parse(find_nt("root"));
242249 pop_source();
243250 }
284291 flag=1;
285292 while(scope)
286293 {
287 oldrule = avl_locate(scope->rules,rule);
288 if(oldrule) break;
289 scope=scope->previous;
294 oldrule = avl_locate(scope->rules,rule);
295 if(oldrule) break;
296 scope=scope->previous;
290297 }
291298 if(oldrule)
292299 {
293 /* rule oscura oldrule */
294 rule->table_backptr=oldrule->table_backptr;
295 *(rule->table_backptr) = rule;
296 oldrule->table_backptr = 0;
297 oldrule->next_rule = rule;
298 rule->next_rule = 0;
299 rule->prev_rule = oldrule;
300 }
300 /* rule oscura oldrule */
301 rule->table_backptr=oldrule->table_backptr;
302 *(rule->table_backptr) = rule;
303 oldrule->table_backptr = 0;
304 oldrule->next_rule = rule;
305 rule->next_rule = 0;
306 rule->prev_rule = oldrule;
307 }
301308 else
302 {
303 /* rule e' nuova */
304 if(dst_scope->enabled)
305 link_rule(rule);
306 }
309 {
310 /* rule e' nuova */
311 if(dst_scope->enabled)
312 link_rule(rule);
313 }
307314 }
308315 }
309316 }
310317
311318 /*---------------------------------------------------------------------------*/
312319
313 delete_scope(name)
314 char *name;
320 void delete_scope(char *name)
315321 {
316322 int i,j;
317323 /*void free_rule();*/
377383 /*---------------------------------------------------------------------------*/
378384
379385
380 list_all_rules() {do_list_rules(0,0);}
381 list_all_krules() {do_list_rules(0,1);}
382 list_rules(s)char*s; {do_list_rules(s,0);}
383 list_krules(s)char*s; {do_list_rules(s,1);}
384
385 /*---------------------------------------------------------------------------*/
386
387 do_list_rules(sintname,kflag)
388 char *sintname;
389 int kflag;
386 int list_all_rules(void) {do_list_rules(0,0); return 0;}
387 int list_all_krules(void) {do_list_rules(0,1); return 0;}
388 int list_rules(char *s) {do_list_rules(s,0); return 0;}
389 int list_krules(char *s) {do_list_rules(s,1); return 0;}
390
391 /*---------------------------------------------------------------------------*/
392
393 void do_list_rules(char *sintname, int kflag)
390394 {
391395 struct s_scope *scope;
392396 int i;
429433 /*---------------------------------------------------------------------------*/
430434
431435
432 write_rules(filename)
433 char *filename;
436 int write_rules(char *filename)
434437 {
435438 struct s_scope *scope;
436439 int i;
437440 Uchan = fopen(filename,"a");
438 if(!Uchan) {zz_error(ERROR,"Unable to write %s\n",filename);return;}
441 if(!Uchan) {zz_error(ERROR,"Unable to write %s\n",filename);return 1;}
439442 printf("RULES segment %d -> (%s)\n",cur_segment_id,filename);
440443 scope = top_scope;
441444 while(scope)
450453 fclose(Uchan);
451454 Uchan=0;
452455 cur_segment_id++;
456 return 0;
453457 }
454458
455459 /*---------------------------------------------------------------------------*/
2626
2727 #include <stdio.h>
2828 #include <stdint.h>
29 #include <stdlib.h>
30 #include <string.h>
2931 #include <errno.h>
3032
3133 #include "avl.h"
3335 #include "list.h"
3436 #include "trace.h"
3537 #include "source.h"
38 #include "rule.h"
39
40 /*PROTOTYPES*/
41 int parse(struct s_nt *);
42 void get_extension(char *, char *);
43 int change_extension(char *, const char *);
3644
3745 int (*find_prompt_proc)()=0;
3846 int (*source_line_routine)()=0;
141149
142150 /*--------------------------------------------------------------------*/
143151
144 pop_source()
152 void pop_source(void)
145153 {
146154 struct s_source *next;
147155 if(!cur_source) return;
166174 /*--------------------------------------------------------------------*/
167175
168176 // Initialization function for file source:
169 source_file(filename)
170 char *filename;
177 int source_file(char *filename)
171178 {
172179 FILE *chan;
173180 chan = fopen(filename,"r");
189196 /*--------------------------------------------------------------------*/
190197
191198
192 source_pipe()
199 int source_pipe(void)
193200 {
194201 new_source(next_token_file);
195202
204211
205212 /*--------------------------------------------------------------------*/
206213
207 source_list(list,id)
208 struct s_content *list;
209 void *id;
214 int source_list(struct s_content *list, void *id)
210215 {
211216 if(list->tag!=tag_list)
212217 {
229234 /*
230235 blocca lo stream di input. un successivo next_token ritornera' EOF
231236 */
232 stop_source()
237 void stop_source(void)
233238 {
234239 if(cur_source)
235240 cur_source->eof = 1;
241246 /**
242247 * Read the next token
243248 */
244 next_token(token)
245 struct s_content *token;
249 int next_token(struct s_content *token)
246250 {
247251 int status;
248252
486490 /*--------------------------------------------------------------------*/
487491
488492
489 source_line(source)
493 int source_line(source)
490494 struct s_source *source;
491495 {
492496 return source->line_n;
496500 /*--------------------------------------------------------------------*/
497501
498502
499 get_current_line()
503 int get_current_line(void)
500504 {
501505 struct s_source *source;
502506 int sp;
516520
517521 /*--------------------------------------------------------------------*/
518522
519 char *get_source_name()
523 char *get_source_name(void)
520524 {
521525 if(!cur_source)
522526 return "NOSOURCE";
528532 /*--------------------------------------------------------------------*/
529533
530534
531 get_source_line()
535 int get_source_line(void)
532536 {
533537 if(!cur_source)
534538 return 0;
538542
539543 /*--------------------------------------------------------------------*/
540544
541 get_source_file(buffer)
542 char *buffer;
545 void get_source_file(char *buffer)
543546 {
544547 int i;
545548 struct s_source *source;
595598 /*--------------------------------------------------------------------*/
596599
597600
598 fprint_source_position(chan,print_action_flag)
601 void fprint_source_position(chan,print_action_flag)
599602 FILE *chan;
600603 int print_action_flag;
601604 {
687690 /*--------------------------------------------------------------------*/
688691
689692
690 pretend_eof()
693 int pretend_eof(void)
691694 {
692695 if(cur_source) cur_source->eof=1;
693 }
694
695
696 /*--------------------------------------------------------------------*/
697
698 read_once_only(id)
699 char *id;
696 return 0;
697 }
698
699
700 /*--------------------------------------------------------------------*/
701
702 int read_once_only(char *id)
700703 {
701704 struct node {char *id;} *p;
702705 static TREE *tree=0;
713716 {
714717 if(cur_source) cur_source->eof=1;
715718 }
719 return 0;
716720 }
717721
718722 /*---------------------------------------------------------------------*/
2121 #include <stdlib.h>
2222 #include <string.h>
2323 #include <dlfcn.h>
24 #include <ctype.h>
25
2426 #include "zlex.h"
2527 #include "list.h"
2628 #include "rule.h"
3436 extern FILE *zz_chanout;
3537 extern struct s_content zz_ret_value;
3638
39 /*PROTOTYPES*/
40 char *get_source_name(void);
41 int get_source_line(void);
42 void error_token(struct s_content *);
43 void error_head(int);
44 void error_tail_1(void);
45 int parse(struct s_nt *);
46 void show_zlex_memory(void);
47 void show_rule_memory(void);
48 int source_file(char *);
49 void pop_source(void);
50 void dumpnet(char *);
51 int change_extension(char *, const char *);
52 int source_list(struct s_content *list, void *id);
3753
3854 const char* zz_includes = "";
3955
136152
137153 /*----------------------------------------------------------------------------*/
138154
139 s_print(list)
140 struct s_list *list;
155 int s_print(struct s_list *list)
141156 {
142157 int i;
143158
152167
153168 /*---------------------------------------------------------------------------*/
154169
155 s_error(list)
156 struct s_list *list;
170 int s_error(struct s_list *list)
157171 {
158172 int i;
159173 error_head(2);
167181
168182 /*---------------------------------------------------------------------------*/
169183
170 s_dump(argc,argv,ret)
171 int argc;
172 struct s_content argv[],*ret;
184 int s_dump(int argc, struct s_content argv[], struct s_content* ret)
173185 {
174186 int i;
175187 fprintz(zz_chanout,"argc=%d\n",argc);
181193
182194 /*---------------------------------------------------------------------------*/
183195
184 int s_param_assign(argc,argv,ret)
185 int argc;
186 struct s_content argv[],*ret;
196 int s_param_assign(int argc, struct s_content argv[], struct s_content* ret)
187197 {
188198 struct s_content value;
189199 value=argv[1];
196206
197207 /*---------------------------------------------------------------------------*/
198208
199 s_param_g_assign(int argc, struct s_content *argv , struct s_content*ret)
209 int s_param_g_assign(int argc, struct s_content argv[], struct s_content* ret)
200210 {
201211 struct s_content value;
202212 value=argv[1];
209219
210220 /*---------------------------------------------------------------------------*/
211221
212 s_param_gn_assign(int argc, struct s_content argv[], struct s_content *ret)
222 int s_param_gn_assign(int argc, struct s_content argv[], struct s_content* ret)
213223 {
214224 int delta;
215225 struct s_content value;
225235 /*----------------------------------------------------------------------------*/
226236
227237
228 s_dumpnet(argc,argv,ret)
229 int argc;
230 struct s_content argv[],*ret;
238 int s_dumpnet(int argc, struct s_content argv[], struct s_content* ret)
231239 {
232240 if(argc<=0 || argv[0].tag!=tag_ident)
233241 {
234242 zz_error(ERROR,"dumpnet: bad argument");return 0;
235243 }
236 dumpnet(s_content_value(argv[0]));
244 dumpnet(s_content_svalue(argv[0]));
237245 return 1;
238246 }
239247
241249 /*--------------------------------------------------------------------------*/
242250
243251
244 s_trace(trace)
252 int s_trace(trace)
245253 int trace;
246254 {
247255 zztrace = trace;
251259 /*---------------------------------------------------------------------------*/
252260
253261
254 s_eq(int argc, struct s_content argv[], struct s_content* ret)
262 int s_eq(int argc, struct s_content argv[], struct s_content* ret)
255263 {
256264 ret->tag=tag_int;
257265
279287
280288 /*---------------------------------------------------------------------------*/
281289
282 s_ne(argc,argv,ret)
283 int argc;
284 struct s_content argv[],*ret;
290 int s_ne(int argc, struct s_content argv[], struct s_content* ret)
285291 {
286292 if(s_eq(argc,argv,ret)) {
287293 s_content_value(*ret) = ! (int)s_content_value(*ret);
293299
294300 /*---------------------------------------------------------------------------*/
295301
296 s_ge(argc,argv,ret)
297 int argc;
298 struct s_content argv[],*ret;
302 int s_ge(int argc, struct s_content argv[], struct s_content* ret)
299303 {
300304 ret->tag=tag_int;
301305
315319
316320 /*---------------------------------------------------------------------------*/
317321
318 s_gt(argc,argv,ret)
319 int argc;
320 struct s_content argv[],*ret;
322 int s_gt(int argc, struct s_content argv[], struct s_content* ret)
321323 {
322324 ret->tag=tag_int;
323325
337339
338340 /*---------------------------------------------------------------------------*/
339341
340 s_le(argc,argv,ret)
341 int argc;
342 struct s_content argv[],*ret;
342 int s_le(int argc, struct s_content argv[], struct s_content* ret)
343343 {
344344 if(s_gt(argc,argv,ret)) {
345345 s_content_value(*ret) = ! (int)s_content_value(*ret);
351351
352352 /*---------------------------------------------------------------------------*/
353353
354 s_lt(argc,argv,ret)
355 int argc;
356 struct s_content argv[],*ret;
354 int s_lt(int argc, struct s_content argv[], struct s_content* ret)
357355 {
358356 if(s_ge(argc,argv,ret)) {
359357 s_content_value(*ret) = !s_content_value(*ret);
365363
366364 /*---------------------------------------------------------------------------*/
367365
368 s_add(argc,argv,ret)
369 int argc;
370 struct s_content argv[],*ret;
366 int s_add(int argc, struct s_content argv[], struct s_content* ret)
371367 {
372368 struct s_tag *targetType = s_target_type(argc, argv);
373369
400396 /*----------------------------------------------------------------------------*/
401397
402398
403 s_boolean_and(argc, argv, ret)
404 int argc;
405 struct s_content argv[], *ret;
399 int s_boolean_and(int argc, struct s_content argv[], struct s_content* ret)
406400 {
407401 if (argc != 2) {
408402 zz_error(ERROR, "Error in s_boolean_and: wrong number of arguments(%i)", argc);
433427 /*----------------------------------------------------------------------------*/
434428
435429
436 s_boolean_or(argc, argv, ret)
437 int argc;
438 struct s_content argv[], *ret;
430 int s_boolean_or(int argc, struct s_content argv[], struct s_content* ret)
439431 {
440432 if (argc != 2) {
441433 zz_error(ERROR, "Error in s_boolean_or: wrong number of arguments(%i)", argc);
466458 /*----------------------------------------------------------------------------*/
467459
468460
469 s_sub(argc,argv,ret)
470 int argc;
471 struct s_content argv[],*ret;
461 int s_sub(int argc, struct s_content argv[], struct s_content* ret)
472462 {
473463 struct s_tag *targetType = s_target_type(argc, argv);
474464
494484
495485 /*---------------------------------------------------------------------------*/
496486
497 s_mult(argc,argv,ret)
498 int argc;
499 struct s_content argv[],*ret;
487 int s_mult(int argc, struct s_content argv[], struct s_content* ret)
500488 {
501489 struct s_tag *targetType = s_target_type(argc, argv);
502490
521509
522510 /*----------------------------------------------------------------------------*/
523511
524 s_div(argc,argv,ret)
525 int argc;
526 struct s_content argv[],*ret;
512 int s_div(int argc, struct s_content argv[], struct s_content* ret)
527513 {
528514 struct s_tag *targetType = s_target_type(argc, argv);
529515
554540
555541 /*----------------------------------------------------------------------------*/
556542
557 s_chs(argc,argv,ret) /* s_chs - change of sign */
558 int argc;
559 struct s_content argv[],*ret;
543 /* s_chs - change of sign */
544 int s_chs(int argc, struct s_content argv[], struct s_content* ret)
560545 {
561546 if(argc!=1) {
562547 zz_error(ERROR,"chs: bad argument number");
596581
597582 /*--------------------------------------------------------------------------*/
598583
599 s_strcat(argc,argv,ret)
600 int argc;
601 struct s_content argv[],*ret;
584 int s_strcat(int argc, struct s_content argv[], struct s_content* ret)
602585 {
603586 char buffer[256];
604587 char *w,*s;
654637
655638 /*----------------------------------------------------------------------------*/
656639
657 s_return(argc,argv,ret)
658 int argc;
659 struct s_content argv[],*ret;
640 int s_return(int argc, struct s_content argv[], struct s_content* ret)
660641 {
661642 zz_ret_value=argv[0];
662643
670651
671652 /*----------------------------------------------------------------------------*/
672653
673 s_exec(argc,argv,ret)
674 int argc;
675 struct s_content argv[],*ret;
676 {
677 source_list(&argv[0]);
654 int s_exec(int argc, struct s_content argv[], struct s_content* ret)
655 {
656 source_list(&argv[0], NULL);
678657 parse(find_nt("root"));
679658 pop_source();
680659 return 1;
682661
683662 /*----------------------------------------------------------------------------*/
684663
685 s_dumplist(argc,argv,ret)
686 int argc;
687 struct s_content argv[];
688 int ret;
664 int s_dumplist(int argc, struct s_content argv[], struct s_content* ret)
689665 {
690666 int i;
691667 struct s_list *lst;
699675
700676 /*--------------------------------------------------------------------------*/
701677
702 s_foreach(argc,argv,ret)
703 int argc;
704 struct s_content argv[],*ret;
678 int s_foreach(int argc, struct s_content argv[], struct s_content* ret)
705679 {
706680 int i,created,rr;
707681 char *paramname;
718692 {
719693 rr=set_param(paramname,lst->array+i);
720694 if(i==0) created=rr;
721 source_list(&blk);
695 source_list(&blk, NULL);
722696 parse(find_nt("root"));
723697 pop_source();
724698 }
728702
729703 /*--------------------------------------------------------------------------*/
730704
731 s_for(argc,argv,ret)
732 int argc;
733 struct s_content argv[],*ret;
705 int s_for(int argc, struct s_content argv[], struct s_content* ret)
734706 {
735707 int from,to,step,i,created,rr;
736708 char *paramname;
758730 s_content_value(paramval)=i;
759731 rr=set_param(paramname,&paramval);
760732 if(i==from) created=rr;
761 source_list(&blk);
733 source_list(&blk, NULL);
762734 parse(find_nt("root"));
763735 pop_source();
764736 }
778750 */
779751
780752 /* Echo back an argument surrounded by parens as a list (with parens) */
781 s_condecho_passparens(argc,argv, ret)
782 int argc;
783 struct s_content argv[], *ret;
753 int s_condecho_passparens(int argc, struct s_content argv[], struct s_content* ret)
784754 {
785755 struct s_content tmp;
786756
801771 }
802772
803773
804 s_condecho_chs(argc,argv,ret)
805 int argc;
806 struct s_content argv[], *ret;
774 int s_condecho_chs(int argc, struct s_content argv[], struct s_content* ret)
807775 {
808776 struct s_content tmp;
809777
824792 Called by unary and binary loop operations
825793 to relect arguments while retaining operators.
826794 */
827 s_condecho(argc,argv, action, ret)
795 int s_condecho(argc,argv, action, ret)
828796 int argc;
829797 char *action;
830798 struct s_content argv[], *ret;
854822 return 1;
855823 }
856824
857 s_condecho_and(argc,argv,ret)
858 int argc;
859 struct s_content argv[], *ret;
825 int s_condecho_and(int argc, struct s_content argv[], struct s_content* ret)
860826 {
861827 return s_condecho(argc, argv, "&&", ret);
862828 }
863829
864 s_condecho_or(argc,argv,ret)
865 int argc;
866 struct s_content argv[], *ret;
830 int s_condecho_or(int argc, struct s_content argv[], struct s_content* ret)
867831 {
868832 return s_condecho(argc, argv, "||", ret);
869833 }
870834
871 s_condecho_add(argc,argv,ret)
872 int argc;
873 struct s_content argv[], *ret;
835 int s_condecho_add(int argc, struct s_content argv[], struct s_content* ret)
874836 {
875837 return s_condecho(argc, argv, "+", ret);
876838 }
877839
878 s_condecho_sub(argc,argv,ret)
879 int argc;
880 struct s_content argv[], *ret;
840 int s_condecho_sub(int argc, struct s_content argv[], struct s_content* ret)
881841 {
882842 return s_condecho(argc, argv, "-", ret);
883843 }
884844
885 s_condecho_mult(argc,argv,ret)
886 int argc;
887 struct s_content argv[], *ret;
845 int s_condecho_mult(int argc, struct s_content argv[], struct s_content* ret)
888846 {
889847 return s_condecho(argc, argv, "*", ret);
890848 }
891849
892 s_condecho_div(argc,argv,ret)
893 int argc;
894 struct s_content argv[], *ret;
850 int s_condecho_div(int argc, struct s_content argv[], struct s_content* ret)
895851 {
896852 return s_condecho(argc, argv, "/", ret);
897853 }
898854
899 s_condecho_eq(argc,argv,ret)
900 int argc;
901 struct s_content argv[], *ret;
855 int s_condecho_eq(int argc, struct s_content argv[], struct s_content* ret)
902856 {
903857 return s_condecho(argc, argv, "==", ret);
904858 }
905859
906 s_condecho_ne(argc,argv,ret)
907 int argc;
908 struct s_content argv[], *ret;
860 int s_condecho_ne(int argc, struct s_content argv[], struct s_content* ret)
909861 {
910862 return s_condecho(argc, argv, "!=", ret);
911863 }
912864
913 s_condecho_ge(argc,argv,ret)
914 int argc;
915 struct s_content argv[], *ret;
865 int s_condecho_ge(int argc, struct s_content argv[], struct s_content* ret)
916866 {
917867 return s_condecho(argc, argv, ">=", ret);
918868 }
919869
920 s_condecho_gt(argc,argv,ret)
921 int argc;
922 struct s_content argv[], *ret;
870 int s_condecho_gt(int argc, struct s_content argv[], struct s_content* ret)
923871 {
924872 return s_condecho(argc, argv, ">", ret);
925873 }
926874
927 s_condecho_le(argc,argv,ret)
928 int argc;
929 struct s_content argv[], *ret;
875 int s_condecho_le(int argc, struct s_content argv[], struct s_content* ret)
930876 {
931877 return s_condecho(argc, argv, "<=", ret);
932878 }
933879
934 s_condecho_lt(argc,argv,ret)
935 int argc;
936 struct s_content argv[], *ret;
880 int s_condecho_lt(int argc, struct s_content argv[], struct s_content* ret)
937881 {
938882 return s_condecho(argc, argv, "<", ret);
939883 }
941885 /*--------------------------------------------------------------------------*/
942886
943887
944 s_do(argc,argv,ret)
945 int argc;
946 struct s_content argv[], *ret;
888 int s_do(int argc, struct s_content argv[], struct s_content* ret)
947889 {
948890 s_do_while_loops(argc,argv,&ret,0);
949891 }
950892
951 s_while(argc,argv,ret)
952 int argc;
953 struct s_content argv[], *ret;
893 int s_while(int argc, struct s_content argv[], struct s_content* ret)
954894 {
955895 s_do_while_loops(argc,argv,&ret,1);
956896 }
962902 * while loop for each pass of the loop (different from 'for' loop
963903 * where interpretation is only done at parse of loop).
964904 */
965 s_do_while_loops(argc,argv,ret,while_loop)
905 int s_do_while_loops(argc,argv,ret,while_loop)
966906 int argc;
967907 struct s_content argv[], *ret;
968908 int while_loop;
1052992 while ( loop_control_flag )
1053993 {
1054994 // Execute the code block of the loop
1055 source_list(&blk);
995 source_list(&blk, NULL);
1056996
1057997 // If there is a parse error in the loop body break out of loop
1058998 if (!parse(find_nt("root"))) {
10871027 /*--------------------------------------------------------------------------*/
10881028
10891029
1090 s_if(argc,argv,ret)
1091 int argc;
1092 struct s_content argv[],*ret;
1030 int s_if(int argc, struct s_content argv[], struct s_content* ret)
10931031 {
10941032 int i,flag;
10951033 char *paramname;
10991037
11001038 if(s_content_value(argv[0]))
11011039 {
1102 source_list(&blk);
1040 source_list(&blk, NULL);
11031041 parse(find_nt("root"));
11041042 pop_source();
11051043 }
11081046
11091047 /*--------------------------------------------------------------------------*/
11101048
1111 s_ifelse(argc,argv,ret)
1112 int argc;
1113 struct s_content argv[],*ret;
1049 int s_ifelse(int argc, struct s_content argv[], struct s_content* ret)
11141050 {
11151051 int i,flag;
11161052 char *paramname;
11241060 {
11251061 blk = argv[2];
11261062 }
1127 source_list(&blk);
1063 source_list(&blk, NULL);
11281064 parse(find_nt("root"));
11291065 pop_source();
11301066 }
11451081
11461082 /*--------------------------------------------------------------------------*/
11471083
1148 s_include(argc,argv,ret)
1149 int argc;
1150 struct s_content argv[],*ret;
1084 int s_include(int argc, struct s_content argv[], struct s_content* ret)
11511085 {
11521086 char filename[FILENAME_MAX],type[40];
11531087
11921126
11931127 /*--------------------------------------------------------------------------*/
11941128
1195 s_add_includedir(argc,argv,ret)
1196 int argc;
1197 struct s_content argv[],*ret;
1129 int s_add_includedir(int argc, struct s_content argv[], struct s_content* ret)
11981130 {
11991131 zz_assert(argc==1);
12001132 if (zz_num_includedirs == MAX_INCLUDEDIRS-1) {
12081140
12091141 /*--------------------------------------------------------------------------*/
12101142
1211 s_print_includedirs(argc,argv,ret)
1212 int argc;
1213 struct s_content argv[],*ret;
1143 int s_print_includedirs(int argc, struct s_content argv[], struct s_content* ret)
12141144 {
12151145 int i;
12161146 fprintf(zz_chanout, "Default Include Directories:\n");
12211151
12221152 /*--------------------------------------------------------------------------*/
12231153
1224 s_include_default(argc,argv,ret)
1225 int argc;
1226 struct s_content argv[],*ret;
1154 int s_include_default(int argc, struct s_content argv[], struct s_content* ret)
12271155 {
12281156 char filename[512],type[40];
12291157 int i;
13271255
13281256 /*----------------------------------------------------------------------------*/
13291257
1330 dump_memory_usage()
1258 int dump_memory_usage(void)
13311259 {
13321260 char cmd[256];
13331261 strcpy(cmd,"ps -u");
13411269 /*---------------------------------------------------------------------------*/
13421270
13431271
1344 s_extract(argc,argv,ret)
1345 int argc;
1346 struct s_content argv[],*ret;
1272 int s_extract(int argc, struct s_content argv[], struct s_content* ret)
13471273 {
13481274 struct s_content *cnt;
13491275 struct s_content *list_extract();
13611287
13621288 /*---------------------------------------------------------------------------*/
13631289
1364 s_list_length(argc,argv,ret)
1365 int argc;
1366 struct s_content argv[],*ret;
1290 int s_list_length(int argc, struct s_content argv[], struct s_content* ret)
13671291 {
13681292 struct s_content *cnt;
13691293 struct s_content *list_extract();
13731297 }
13741298
13751299 /*----------------------------------------------------------------------------*/
1376 s_string_length(int argc, struct s_content argv[], struct s_content* ret)
1300
1301 int s_string_length(int argc, struct s_content argv[], struct s_content* ret)
13771302 {
13781303 struct s_content *cnt;
13791304 ret->tag = tag_int;
13851310 /*----------------------------------------------------------------------------*/
13861311
13871312 // Implement split function for zz simillar to strtok() c function.
1388 s_split(argc,argv,ret)
1389 int argc;
1390 struct s_content argv[], *ret;
1313 int s_split(int argc, struct s_content argv[], struct s_content* ret)
13911314 {
13921315 char *pch;
13931316 char *srcstr;
14381361 /*----------------------------------------------------------------------------*/
14391362
14401363
1441 show_sys_memory()
1364 void show_sys_memory(void)
14421365 {
14431366 PRINTMEM("sys.qstring",sys_qstring_mem)
14441367 }
14451368
14461369 /*---------------------------------------------------------------------------*/
14471370
1448 subtag(tagson_name,tagparent_name)
1449 char *tagson_name,*tagparent_name;
1371 int subtag(char *tagson_name, char *tagparent_name)
14501372 {
14511373 struct s_tag *tagson,*tagparent;
14521374 tagson = find_tag(tagson_name);
14541376 tagson->delete = tagparent->delete;
14551377 tagson->param_on = tagparent->param_on;
14561378 tagson->param_off = tagparent->param_off;
1457 }
1458
1459 /*---------------------------------------------------------------------------*/
1460
1461 show_memory()
1379 return 0;
1380 }
1381
1382 /*---------------------------------------------------------------------------*/
1383
1384 void show_memory(void)
14621385 {
14631386 printf("Memory usage\n");
14641387 show_zlex_memory();
14811404
14821405
14831406
1484 init_time()
1407 void init_time(void)
14851408 {
14861409 times (&Time);
14871410 Start_Time = Time.proc_user_time;
14881411 }
14891412
14901413
1491 get_time()
1414 int get_time(void)
14921415 {
14931416 int t;
14941417 times (&Time);
14991422
15001423
15011424
1502 proc_beep(argc,argv,ret)
1503 int argc;
1504 struct s_content argv[],*ret;
1425 int proc_beep(int argc, struct s_content argv[], struct s_content *ret)
15051426 {
15061427 char *s;
15071428 int line_n;
15081429 int time;
15091430 float sec;
1510 static count=0;
1431 static int count=0;
15111432 time = get_time();
15121433 sec = (float)time*0.01;
15131434 if(argc==1)
15141435 printz("** %z ** ",&argv[0]);
15151436 else
15161437 printf("** %d ** ",count++);
1517 s=(char*)get_source_name();
1438 s=get_source_name();
15181439 line_n=get_source_line();
15191440 printf("TIME %4.2fs FILE %s LINE %d\n",sec,s,line_n);
15201441 return 1;
15261447 static struct s_content bra,ket;
15271448
15281449
1529 s_append_bra(argc,argv,ret)
1530 int argc;
1531 struct s_content argv[],*ret;
1450 int s_append_bra(int argc, struct s_content argv[], struct s_content *ret)
15321451 {
15331452 if(argc!=1 || argv[0].tag!=tag_list)
15341453 {printf("error - s_append_bra; bad parameters\n");exit(1);}
15471466
15481467 /*---------------------------------------------------------------------------*/
15491468
1550 s_append_ket(argc,argv,ret)
1551 int argc;
1552 struct s_content argv[],*ret;
1469 int s_append_ket(int argc, struct s_content argv[], struct s_content *ret)
15531470 {
15541471 if(argc!=1 || argv[0].tag!=tag_list)
15551472 {printf("error - s_append_ket; bad parameters\n");exit(1);}
16101527 int zz_inttohex(int i)
16111528 {
16121529 char* q=calloc(20,sizeof(char));
1613 sprintf(q,"0x%x\0",i);
1530 sprintf(q,"0x%x",i);
16141531 return (int)q;
16151532 }
16161533
17521669 */
17531670 /*---------------------------------------------------------------------------*/
17541671
1755 int change_extension(char *fullfilename,char *filetype) {
1672 int change_extension(char *fullfilename, const char *filetype) {
17561673 char tmp[256],*r,*s,*t;
17571674 int i;
17581675 if(*filetype=='.') filetype++;
3838 #include "mem.h"
3939 #include "table.h"
4040
41 /*FORWARDS*/
42 void remove_dot(struct s_dot *);
43 void print_rule(struct s_rule *);
44
4145 static int table_mem=0;
4246 extern struct s_nt *nt_any,*nt_param,*nt_gparam;
4347
4650
4751 /* CONFRONTO DI T-TRAN */
4852
49 ttrancmp(p1,p2)
50 struct s_term_tran *p1,*p2;
53 int ttrancmp(void *vp1, void *vp2)
5154 {
5255 struct s_content *t1,*t2;
56 struct s_term_tran *p1 = vp1;
57 struct s_term_tran *p2 = vp2;
5358 t1 = &(p1->term);
5459 t2 = &(p2->term);
5560 if(t1->tag<t2->tag) return -1;
6772
6873 /*----------------------------------------------------------------------------*/
6974
70 struct s_dot *create_dot(nt)
71 struct s_nt *nt;
75 struct s_dot *create_dot(struct s_nt *nt)
7276 {
7377 static int dot_count=0;
7478 struct s_dot *dot;
110114
111115 /*----------------------------------------------------------------------------*/
112116
113 remove_dot(dot)
114 struct s_dot *dot;
117 void remove_dot(struct s_dot *dot)
115118 {
116119 if(!dot)return;
117120 avl_release(dot->termtree,remove_term_tran);
283286
284287 /*---------------------------------------------------------------------------*/
285288
286 link_rule(rule)
287 struct s_rule *rule;
289 int link_rule(struct s_rule *rule)
288290 {
289291 int bead_n;
290292 struct s_bead *bead;
313315 dot->rule = rule;
314316 dot->rule_count++;
315317 rule->table_backptr = &(dot->rule);
316 }
317
318
319 /*----------------------------------------------------------------------------*/
320
321 unlink_rule(rule)
322 struct s_rule *rule;
318 return 0;
319 }
320
321
322 /*----------------------------------------------------------------------------*/
323
324 int unlink_rule(struct s_rule *rule)
323325 {
324326 int bead_n;
325327 struct s_bead *bead;
353355 else if(dot->rule != 0) /* work around for popvoidrule bug */
354356 { /* why can dot->rule be null ??? */
355357 zz_error(INTERNAL_ERROR,"unlink_rule: rule mismatch");
356 printf("| old rule is (0x%x)",dot->rule);print_rule(dot->rule);//printf(" (%p)\n", dot->rule);
358 printf("| old rule is (0x%x)",(int)dot->rule);print_rule(dot->rule);//printf(" (%p)\n", dot->rule);
357359 printf("| unlinking rule is ");print_rule(rule);printf("\n");
358360 abort();
359361 }
360362 }
361 }
362
363
364 /*----------------------------------------------------------------------------*/
365
366 show_table_mem()
363 return 0;
364 }
365
366
367 /*----------------------------------------------------------------------------*/
368
369 void show_table_mem(void)
367370 {
368371 PRINTMEM("table",table_mem)
369372 }
3333 #include "param.h"
3434 #include "trace.h"
3535 #include "sys.h"
36
37 /*PROTOTYPES*/
38 void pop_source(void);
39 int source_list(struct s_content *list, void *id);
40 void kernel(void);
41 void zkernel(void);
42 int parse(struct s_nt *start_nt);
3643
3744 static const char *std_prompt = "ozz> "; // Default prompt
3845
2020 #include "zlex.h"
2121 #include "kernel.h"
2222
23 zkernel()
23 void zkernel(void)
2424 {
2525 /* redefinition of the syntax */
2626
117117 struct s_content *cnt;
118118 {
119119 //zz_assert(cnt && s_content_tag(*cnt)==tag_qstring);
120 strcpy(buffer,(char*)s_content_value(*cnt));
120 strcpy(buffer, s_content_svalue(*cnt));
121121 }
122122
123123 int fprint_string(chan,cnt)
125125 struct s_content *cnt;
126126 {
127127 //zz_assert(cnt && s_content_tag(*cnt)==tag_qstring);
128 fprintf(chan,"%s",s_content_value(*cnt));
128 fprintf(chan,"%s", s_content_svalue(*cnt));
129129 }
130130
131131 /*----------------------------------------------------------------------------*/
449449 }
450450 #endif
451451
452 init_zlex()
452 void init_zlex(void)
453453 {
454454 if(init_zlex_done) return;
455455 init_zlex_done=1;
609609 /*----------------------------------------------------------------------------*/
610610
611611
612 zlex_set_precedence(cnt,prec,left_assoc)
612 void zlex_set_precedence(cnt,prec,left_assoc)
613613 struct s_content *cnt;
614614 int prec,left_assoc;
615615 {
693693
694694 /*----------------------------------------------------------------------------*/
695695
696 std_len(cnt)
697 struct s_content *cnt;
696 int std_len(struct s_content *cnt)
698697 {
699698 //return strlen(cnt->tag->name)+9;
700699 zz_assert(!"any use????");
11561155
11571156 /*----------------------------------------------------------------------------*/
11581157
1159 show_zlex_memory()
1158 void show_zlex_memory(void)
11601159 {
11611160 PRINTMEM("zlex.qstring.mex",zlex_qstring_mem)
11621161 PRINTMEM("zlex.strsaved.mem",zlex_strsaved_mem)
11991198 /*------------------------------------------------------------------------*/
12001199
12011200
1202 ignore_block()
1201 void ignore_block(void)
12031202 {
12041203 ignore_block_flag = 1;
12051204 braket_level = 0;
4444 extern int init_zlex_done;
4545 #endif
4646
47 void init_zlex(void);
4748 #define INIT_ZLEX {if(!init_zlex_done)init_zlex();}
4849
4950
1919 //#define DEBUG 1
2020
2121 #include <stdint.h>
22 #include <string.h>
23
2224 #include "zlex.h"
2325 #include "rule.h"
2426 #include "err.h"
2527 #include "trace.h"
2628
29 /*PROTOTYPES*/
30 void setaction_return(struct s_content *value, char *tag_name);
31 void setaction_rreturn(void);
32 void setaction_pass(void);
33 void setaction_exelist(struct s_content *list);
34 void setaction_assign(void);
35 void append_nt_bead(char *ntname, char *beadname);
36 void append_t_bead(struct s_content *cnt);
37 void insert_rule(char *, struct s_rule *);
38
2739 static struct {struct s_content bead;char *name;} beads[MAX_RULE_LENGTH];
2840 static int bead_n=0;
2941 static struct {struct s_content cnt;char *tag_name,is_return;}
3345
3446 /* aggiungi una bead alla regola corrente */
3547
36 z_bead(argc,argv,ret)
37 int argc;
38 struct s_content argv[],*ret;
48 int z_bead(int argc, struct s_content argv[], struct s_content *ret)
3949 {
4050 if(bead_n>=MAX_RULE_LENGTH)
4151 {
4252 zz_error(ERROR,"rule too long");
43 return;
53 return 0;
4454 }
4555 beads[bead_n].bead=argv[1];
4656 beads[bead_n].name=(argc==3)?(char*)s_content_value(argv[2]):0;
5262
5363 /* l'azione della regola corrente (zz-action o special) */
5464
55 z_set_action(argc,argv,ret)
56 int argc;
57 struct s_content argv[],*ret;
65 int z_set_action(int argc, struct s_content argv[], struct s_content *ret)
5866 {
5967 cur_action.cnt=argv[0];
6068 cur_action.is_return=0;
6573
6674 /* l'azione della regola corrente (return [as]) */
6775
68 z_set_return_action(argc,argv,ret)
69 int argc;
70 struct s_content argv[],*ret;
76 int z_set_return_action(int argc, struct s_content argv[], struct s_content *ret)
7177 {
7278 cur_action.cnt=argv[0];
7379 cur_action.is_return=1;
8086
8187 /*---------------------------------------------------------------------------*/
8288
89 void do_z_link_rule(char *, char *);
90
8391 /* inserisce una regola nello scope di default */
8492
85 z_link_rule_default(argc,argv,ret)
86 int argc;
87 struct s_content argv[],*ret;
88 {
89 do_z_link_rule(s_content_value(argv[0]),0);
93 int z_link_rule_default(int argc, struct s_content argv[], struct s_content *ret)
94 {
95 do_z_link_rule(s_content_svalue(argv[0]), NULL);
9096 return 1;
9197 }
9298
94100
95101 /* inserisce una regola in uno scope */
96102
97 z_link_rule(argc,argv,ret)
98 int argc;
99 struct s_content argv[],*ret;
100 {
101 do_z_link_rule(s_content_value(argv[1]),s_content_value(argv[0]));
102 return 1;
103 }
104
105 /*---------------------------------------------------------------------------*/
106
107 do_z_link_rule(sint_name,scope_name)
108 char *sint_name,*scope_name;
103 int z_link_rule(int argc, struct s_content argv[], struct s_content *ret)
104 {
105 do_z_link_rule(s_content_svalue(argv[1]), s_content_svalue(argv[0]));
106 return 1;
107 }
108
109 /*---------------------------------------------------------------------------*/
110
111 void do_z_link_rule(char *sint_name, char *scope_name)
109112 {
110113 int i;
111114 struct s_rule *rule;
112115 open_rule(zlex_strsave(sint_name));
113116 for(i=0;i<bead_n;i++)
114117 if(beads[i].name)
115 append_nt_bead(s_content_value(beads[i].bead),beads[i].name);
118 append_nt_bead(s_content_svalue(beads[i].bead),beads[i].name);
116119 else
117120 append_t_bead(&beads[i].bead);
118121 bead_n=0;
142145 cur_action.cnt.tag=tag_none;
143146 s_content_value(cur_action.cnt)=0;
144147 cur_action.is_return=0;
145 return 1;
146148 }
147149
148150 /*---------------------------------------------------------------------------*/
196198 }
197199
198200
199 z_append_term(argc,argv,ret)
200 int argc;
201 struct s_content argv[],*ret;
201 int z_append_term(int argc, struct s_content argv[], struct s_content *ret)
202202 {
203203 append_t_bead(&argv[0]);
204204 return 1;
205205 }
206206
207 z_append_nt(argc,argv,ret)
208 int argc;
209 struct s_content argv[],*ret;
207 int z_append_nt(int argc, struct s_content argv[], struct s_content *ret)
210208 {
211209 append_nt_bead(s_content_value(argv[0]),s_content_value(argv[1]));
212210 return 1;
216214
217215 /*---------------------------------------------------------------------------*/
218216
219 z_set_when_change_action(argc,argv,ret)
220 int argc;
221 struct s_content argv[],*ret;
217 int z_set_when_change_action(int argc, struct s_content argv[], struct s_content *ret)
222218 {
223219 struct s_rule *rule,*get_last_rule();
224220 rule = get_last_rule();
232228
233229 /*---------------------------------------------------------------------------*/
234230
235 z_set_when_exit_scope(argc,argv,ret)
236 int argc;
237 struct s_content argv[],*ret;
231 int z_set_when_exit_scope(int argc, struct s_content argv[], struct s_content *ret)
238232 {
239233 struct s_rule *rule,*get_last_rule();
240234 rule = get_last_rule();
2828 #include <stdlib.h>
2929
3030 #include "zz.h"
31
32 /*PROTOYPES*/
33 void print_error_count(void);
34 void print_usage(void);
3135
3236 int main(argc,argv,env)
3337 int argc;
164168 /*---------------------------------------------------------------------*/
165169
166170
167 print_usage() {
171 void print_usage(void) {
168172 fprintf(stderr,
169173 "usage: ozz [params] [filein [fileout]]\n"
170174 " -q quiet\n"
3636 #include "zlex.h"
3737 #include "trace.h"
3838 #include "source.h"
39 #include "rule.h"
3940
41 /*PROTOTYPES*/
42 int parse(struct s_nt *);
4043 void next_token_tt(struct s_source *src);
4144
4245 /*--------------------------------------------------------------------*/
4447 /**
4548 * Initialization function for using zz with interactive tty interface:
4649 */
47 source_tt()
50 void source_tt(void)
4851 {
4952 struct s_source *src = new_source(next_token_tt);
5053
5255 src->src.tt.prompt = zz_get_prompt();
5356 src->src.tt.old = src->src.tt.s = 0;
5457 src->src.tt.row[0]='\0';
55
56 return 1;
5758 }
5859
5960
6162
6263
6364
64 zz_parse_tt()
65 int zz_parse_tt(void)
6566 {
6667 /* really necessary... hope it doesn't come first in the calling sequence..
6768 if(!zz_chanout)