Annotation of OpenXM_contrib2/asir2000/parse/parse.h, Revision 1.1.1.1
1.1 noro 1: /* $OpenXM: OpenXM/src/asir99/parse/parse.h,v 1.1.1.1 1999/11/10 08:12:34 noro Exp $ */
2: # if defined(THINK_C) || defined(VISUAL)
3: #include <time.h>
4: #else
5: #include <sys/time.h>
6: #include <sys/resource.h>
7: #endif
8: #include <setjmp.h>
9: #ifdef ABS
10: #undef ABS
11: #define ABS(a) ((a)>0?(a):-(a))
12: #endif
13:
14: /* identifiers for expressions */
15:
16: typedef enum {
17: I_BOP, I_COP, I_AND, I_OR, I_NOT, I_CE,
18: I_PRESELF, I_POSTSELF,
19: I_FUNC, I_FUNC_OPT, I_IFUNC, I_MAP, I_PFDERIV,
20: I_ANS, I_PVAR, I_ASSPVAR,
21: I_FORMULA, I_LIST, I_STR, I_NEWCOMP, I_CAR, I_CDR, I_CAST,
22: I_COM, I_PROC, I_INDEX, I_EV, I_TIMER, I_GF2NGEN, I_GFPNGEN, I_LOP,
23: I_OPT, I_GETOPT
24: } fid;
25:
26: /* identifiers for statements */
27:
28: typedef enum {
29: S_BP, S_PFDEF,
30: S_SINGLE, S_CPLX,
31: S_IFELSE, S_FOR, S_DO,
32: S_BREAK, S_RETURN, S_CONTINUE
33: } sid;
34:
35: /* identifiers for comparison operators */
36:
37: typedef enum { C_LT, C_GT, C_LE, C_GE, C_EQ, C_NE } cid;
38:
39: /* identifiers for logical operators */
40:
41: typedef enum { L_LT, L_GT, L_LE, L_GE, L_EQ, L_NE, L_AND, L_OR, L_NOT, L_IMPL, L_REPL, L_EQUIV } lid;
42:
43: /* identifiers for functions */
44:
45: typedef enum { A_UNDEF, A_BIN, A_USR, A_PURE, A_PARI } aid;
46:
47: /* identifiers for indeterminates */
48:
49: typedef enum { V_IND, V_UC, V_PF, V_SR } vid;
50:
51: struct oVS {
52: unsigned int n;
53: unsigned int asize;
54: unsigned int at;
55: unsigned int level;
56: struct oFUNC *usrf;
57: struct oPV *va;
58: NODE opt;
59: };
60:
61: typedef struct oVS *VS;
62:
63: struct oPV {
64: char *name;
65: short attr,type;
66: pointer priv;
67: };
68:
69: typedef struct oPV *PV;
70:
71: struct oIN {
72: char *name;
73: FILE *fp;
74: int ln;
75: struct oIN *next;
76: char *tname;
77: int encoded;
78: short vol;
79: };
80:
81: typedef struct oIN *IN;
82:
83: struct oTKWD {
84: char *name;
85: int token;
86: };
87:
88: struct oARF {
89: char *name;
90: void (*fp)();
91: };
92:
93: typedef struct oARF *ARF;
94:
95: struct oFUNC {
96: char *name;
97: int argc;
98: int type;
99: aid id;
100: union {
101: void (*binf)();
102: struct oUSRF *usrf;
103: struct oPF *puref;
104: } f;
105: };
106:
107: typedef struct oFUNC *FUNC;
108:
109: struct oUSRF {
110: char *fname;
111: short vol;
112: int startl,endl;
113: NODE args;
114: VS pvs;
115: char *desc;
116: struct oSNODE *body;
117: };
118:
119: typedef struct oUSRF *USRF;
120:
121: struct oPF {
122: char *name;
123: int argc;
124: Obj body;
125: V *args;
126: Obj *deriv;
127: NODE ins;
128: int (*pari)();
129: double (*libm)();
130: int (*simplify)();
131: };
132:
133: typedef struct oPF *PF;
134:
135: struct oPFAD {
136: Obj arg;
137: int d;
138: };
139:
140: typedef struct oPFAD *PFAD;
141:
142: struct oPFINS {
143: struct oPF *pf;
144: struct oPFAD ad[1];
145: };
146:
147: typedef struct oPFINS *PFINS;
148:
149: #define NEWPF(p) ((p)=(PF)MALLOC(sizeof(struct oPF)))
150:
151: struct oFNODE {
152: fid id;
153: pointer arg[1];
154: };
155:
156: typedef struct oFNODE *FNODE;
157:
158: #define NEWFNODE(a,b) \
159: ((a)=(FNODE)MALLOC(sizeof(struct oFNODE)+sizeof(pointer)*(b-1)))
160:
161: struct oSNODE {
162: sid id;
163: int ln;
164: pointer arg[1];
165: };
166:
167: typedef struct oSNODE *SNODE;
168:
169: #define NEWSNODE(a,b) \
170: ((a)=(SNODE)MALLOC(sizeof(struct oSNODE)+sizeof(pointer)*(b-1)),(a)->ln=asir_infile->ln)
171:
172: struct oPVI {
173: int pv;
174: NODE index;
175: };
176:
177: typedef struct oPVI *PVI;
178:
179: struct oNODE2 {
180: pointer body1,body2;
181: struct oNODE2 *next;
182: };
183:
184: typedef struct oNODE2 *NODE2;
185:
186: struct ftab {
187: char *name;
188: void (*f)();
189: int argc;
190: };
191:
192: #define MKPVI(a,b,c)\
193: ((a)=(pointer)MALLOC(sizeof(struct oPVI)),((PVI)(a))->pv=(b),((PVI)(a))->index=(c))
194:
195: #define FA0(f) ((f)->arg[0])
196: #define FA1(f) ((f)->arg[1])
197: #define FA2(f) ((f)->arg[2])
198: #define FA3(f) ((f)->arg[3])
199: #define FA4(f) ((f)->arg[4])
200: #define FA5(f) ((f)->arg[5])
201: #define FA6(f) ((f)->arg[6])
202:
203: #define ARG0(a) ((a)->body)
204: #define ARG1(a) (NEXT(a)->body)
205: #define ARG2(a) (NEXT(NEXT(a))->body)
206: #define ARG3(a) (NEXT(NEXT(NEXT(a)))->body)
207: #define ARG4(a) (NEXT(NEXT(NEXT(NEXT((a)))))->body)
208: #define ARG5(a) (NEXT(NEXT(NEXT(NEXT(NEXT((a))))))->body)
209: #define ARG6(a) (NEXT(NEXT(NEXT(NEXT(NEXT(NEXT((a)))))))->body)
210: #define ARG7(a) (NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT((a))))))))->body)
211: #define ARG8(a) (NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT((a)))))))))->body)
212: #define ARG9(a) (NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT((a))))))))))->body)
213: #define ARG10(a) (NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT(NEXT((a)))))))))))->body)
214:
215: #define asir_assert(ptr,id,message)\
216: switch ( id ) {\
217: case O_N: case O_P: case O_R:\
218: if( (ptr) && (OID(ptr) > (id)) ) {\
219: fprintf(stderr,message);\
220: error(" : invalid argument");\
221: }\
222: break;\
223: case O_DP:\
224: if( (ptr) && (OID(ptr) != (id)) ) {\
225: fprintf(stderr,message);\
226: error(" : invalid argument");\
227: }\
228: break;\
229: default:\
230: if( !(ptr) || (OID(ptr) != (id)) ) {\
231: fprintf(stderr,message);\
232: error(" : invalid argument");\
233: }\
234: break;\
235: }
236:
237: #define DEFSIZE 32
238: #define MSB (1<<31)
239: #define GETPV(i,p) \
240: ((int)(i)>=0 ? (int)((p)=CPVS->va[(unsigned int)(i)].priv)\
241: : (int)((p)=GPVS->va[(unsigned int)(i)&(~MSB)].priv))
242: #define ASSPV(i,p) \
243: ((int)(i)>=0 ? (int)(CPVS->va[(unsigned int)(i)].priv=(pointer)(p))\
244: : (int)(GPVS->va[(unsigned int)(i)&(~MSB)].priv=(pointer)(p)))
245:
246: #define NEWNODE2(a) ((a)=(NODE2)MALLOC(sizeof(struct oNODE2)))
247: #define MKNODE2(a,b,c,d) \
248: (NEWNODE2(a),(a)->body1=(pointer)b,(a)->body2=(pointer)c,NEXT(a)=(NODE2)(d))
249: #define BDY1(a) ((a)->body1)
250: #define BDY2(a) ((a)->body2)
251:
252: extern VS GPVS,CPVS,EPVS,APVS;
253: extern ARF addfs, subfs, mulfs, divfs, remfs, pwrfs;
254: extern IN asir_infile;
255: extern NODE usrf,sysf,noargsysf,ubinf,parif,ONENODE;
256: extern int nextbp,nextbplevel;
257: extern int Verbose;
258:
259: #if defined(VISUAL_LIB)
260: #include <w_stdio.h>
261: #undef getc
262: #define getc w_fgetc
263: #undef putc
264: #define putc w_fputc
265: #define fputc w_fputc
266: #define ungetc w_ungetc
267: #define fgets w_fgets
268: #define fputs w_fputs
269: #define printf w_printf
270: #define fprintf w_fprintf
271: #define fflush w_fflush
272: #endif
273:
274: #if defined(THINK_C) || defined(VISUAL)
275: NODE mknode(int,...);
276: FNODE mkfnode(int,fid,...);
277: SNODE mksnode(int,sid,...);
278: void call_usrf(FUNC f,...);
279: #else
280: NODE mknode();
281: FNODE mkfnode();
282: SNODE mksnode();
283: void call_usrf();
284: #endif
285:
286: /* prototypes */
287:
288: #if 1 || defined(THINK_C) || defined(VISUAL)
289: void dp_ptozp2_d(NODE,int,DP,DP,DP *,DP *);
290: void dp_ptozp_d(NODE,int,DP,DP *);
291: void dp_ptozp_d_old(NODE,int,DP,DP *);
292: void dp_vtod(Q *,DP,DP *);
293: void dp_idivv_hist(Q,DP *);
294: void dp_igcdv_hist(DP,Q *);
295: void dp_ptozp2(DP,DP,DP *,DP *);
296: void dp_ptozp(DP,DP *);
297: void dp_nf_tab_mod(DP,LIST *,int,DP *);
298: void dp_lnf_mod(DP,DP,NODE,int,DP *,DP *);
299: void insert_to_node(DL,NODE *,int);
300: int _dl_redble(DL,DL,int);
301: void dp_mbase(NODE,NODE *);
302: void dp_dtov(DP,VECT *);
303: void dp_cont(DP,Q *);
304: void dp_idiv(DP,Q,DP *);
305:
306: int dp_nt(DP);
307: void dp_dehomo(DP,DP *);
308: void dp_homo(DP,DP *);
309: DL lcm_of_DL(int,DL,DL,DL);
310: void dp_rest(DP,DP *);
311: void dp_hm(DP,DP *);
312: void dp_sp_mod(DP,DP,int,DP *);
313: void dp_sp(DP,DP,DP *);
314: void dp_red(DP,DP,DP,DP *,DP *,P *);
315: void dp_subd(DP,DP,DP *);
316: void dp_red_mod(DP,DP,DP,int,DP *,DP *,P *);
317: int dp_redble(DP,DP);
318: int comp_nm(Q *,Q *);
319: void dp_true_nf_mod(NODE,DP,DP *,int,int,DP *,P *);
320: void dp_nf_mod(NODE,DP,DP *,int,int,DP *);
321: void dp_nf_mod_qindex(NODE,DP,DP *,int,int,DP *);
322: void dp_nf_ptozp(NODE,DP,DP *,int,int,DP *);
323: void dp_true_nf(NODE,DP,DP *,int,DP *,P *);
324: void dp_nf(NODE,DP,DP *,int,DP *);
325: void dp_rat(DP,DP *);
326: void dp_mod(DP,int,NODE,DP *);
327: void dp_prim_mod(DP,int,DP *);
328: void dp_prim(DP,DP *);
329: void heu_nezgcdnpz(VL,P *,int,P *);
330: void homogenize_order(struct order_spec *,int,struct order_spec *);
331: int create_order_spec(Obj,struct order_spec *);
332:
333: int dl_equal(int,DL,DL);
334: void qltozl(Q *,int,Q *);
335: int cmpdl_matrix(int,DL,DL);
336: int cmpdl_order_pair(int,DL,DL);
337: int cmpdl_elim(int,DL,DL);
338: int cmpdl_blexrev(int,DL,DL);
339: int cmpdl_bgradrev(int,DL,DL);
340: int cmpdl_brevrev(int,DL,DL);
341: int cmpdl_brevgradlex(int,DL,DL);
342: int cmpdl_bgradlex(int,DL,DL);
343: int cmpdl_blex(int,DL,DL);
344: int cmpdl_revgradlex(int,DL,DL);
345: int cmpdl_gradlex(int,DL,DL);
346: int cmpdl_revlex(int,DL,DL);
347: int cmpdl_lex(int,DL,DL);
348: int compd(VL,DP,DP);
349: void adddl(int,DL,DL,DL *);
350: void divsdc(VL,DP,P,DP *);
351: void muldc(VL,DP,P,DP *);
352: void muldm(VL,DP,MP,DP *);
353: void muld(VL,DP,DP,DP *);
354: void chsgnd(DP,DP *);
355: void subd(VL,DP,DP,DP *);
356: void addd(VL,DP,DP,DP *);
357: int sugard(MP);
358: void nodetod(NODE,DP *);
359: void dtop(VL,VL,DP,P *);
360: void ptod(VL,VL,P,DP *);
361: void initd(struct order_spec *);
362:
363: int mainparse(SNODE *);
364: int exprparse(FUNC,char *,FNODE *);
365: void output_init(void);
366: void GC_init(void);
367: void env_init(void);
368: void soutput_init(char *);
369: void appendparif(NODE *,char *,int (*)(),int);
370: int mmono(P);
371: void mkpow(VL,Obj,Obj,Obj *);
372: void _printdp(DP);
373: int mt_save(char *);
374: int mt_load(char *);
375: void sortbynm(Q *,int);
376: void iqrv(VECT,Q,LIST *);
377: void igcdv(VECT,Q *);
378: void igcdv_estimate(VECT,Q *);
379: void cpp_main(int,char **);
380: int afternl(void);
381: void glob_init();
382: void input_init(FILE *,char *);
383: void asir_terminate(int);
384: void param_init(void);
385: void sprompt(char *);
386: void process_args(int,char **);
387: void sig_init(void);
388: void asir_save_handler(void);
389: void asir_set_handler(void);
390: void asir_reset_handler(void);
391: void resetenv(char *);
392: void fatal(int);
393: void restore_handler(void);
394: void resize_buffer(void);
395: void tty_init(void);
396: void tty_reset(void);
397: void set_timer(int);
398: void reset_timer(void);
399: void int_handler(int);
400: void int_handler(int);
401: void segv_handler(int);
402: void bus_handler(int);
403: void fpe_handler(int);
404: void ill_handler(int);
405: void winch_handler(int);
406: void pipe_handler(int);
407: void usr1_handler(int);
408: void alrm_handler(int);
409: void copyright(void);
410: void kan_init(void);
411: void pushpvs(FUNC);
412: void read_eval_loop(void);
413: void prompt(void);
414: void storeans(pointer);
415: int yyparse(void);
416: void nodetod(NODE,DP *);
417: void poppvs(void);
418: int length(NODE);
419: int get_heapsize(void);
420: int searchpvar(char *);
421: void mkparif(char *,FUNC *);
422: void makevar(char *,P *);
423: void mkpvs(void);
424: void stoarg(char *,int *,char **);
425: void yyerror(char *);
426: void closecurrentinput(void);
427: void asir_terminate(int);
428: void searchasirpath(char *,char **);
429: void get_vars(Obj,VL *);
430: void appendbinf(NODE *,char *,void(*)(),int);
431: void appendubinf(char *,void(*)(),int);
432: void parif_init(void);
433: void sysf_init(void);
434: void makesrvar(FUNC, P *);
435: void sprintexpr(VL,Obj);
436: void printexpr(VL,Obj);
437: void appendvar(VL,V);
438: void change_mvar(VL,P,V,P *);
439: void restore_mvar(VL,P,V,P *);
440: int argc(NODE);
441: void printn(N);
442: void sprintn(N);
443: void printv(VL,V);
444: void sprintv(VL,V);
445: int arf_comp(VL, Obj, Obj);
446: int complist(VL, LIST, LIST);
447: int complist(VL, LIST, LIST);
448: int getcompsize(int);
449: int getpvar(VS,char *,int);
450: int getpvar(VS,char *,int);
451: int gettype(unsigned int);
452: int indextotype(int,int);
453: int loadfile(char *);
454: int loadfiles(NODE);
455: int makepvar(char *);
456: int membertoindex(int,char *);
457: int qcoefp(Obj);
458: int qcoefr(Obj);
459: int rangecheck(Obj,int);
460: int structtoindex(char *);
461: pointer eval(FNODE);
462: pointer evalf(FUNC,FNODE,FNODE);
463: pointer evalif(FNODE,FNODE);
464: pointer evalnode(NODE node);
465: pointer evalpf(PF,NODE);
466: pointer evalparif(FUNC,NODE);
467: pointer evalpv(int,FNODE,pointer);
468: pointer evalstat(SNODE f);
469: void _mkpfins(PF ,Obj *,V *);
470: void appendpfins(V ,V *);
471: void appenduf(char *,FUNC *);
472: void arf_add(VL, Obj, Obj, Obj *);
473: void arf_chsgn(Obj, Obj *);
474: void arf_div(VL, Obj, Obj, Obj *);
475: void arf_init(void);
476: void arf_mul(VL, Obj, Obj, Obj *);
477: void arf_pwr(VL, Obj, Obj, Obj *);
478: void arf_remain(VL, Obj, Obj, Obj *);
479: void arf_sub(VL, Obj, Obj, Obj *);
480: void bp(SNODE);
481: void clearbp(FUNC);
482: void debug(SNODE);
483: void debug_init(void);
484: void delbp(int, char **);
485: void derivr(VL ,Obj ,V ,Obj *);
486: void derivvar(VL ,V ,V ,Obj *);
487: void duppfins(V ,V *);
488: void error(char *);
489: void evalins(PFINS ,int ,Obj *);
490: void evalnodebody(NODE,NODE *);
491: void evalp(VL ,P ,int ,P *);
492: void evalr(VL ,Obj ,int ,Obj *);
493: void evalv(VL ,V ,int ,Obj *);
494: void getarrayp(Obj,NODE,Obj **);
495: void getmember(FNODE,Obj *);
496: void getmemberp(FNODE,Obj **);
497: void help(char *);
498: void instov(PFINS ,V *);
499: void memberofstruct(FNODE,char *,FNODE *);
500: void mkpf(char *,Obj ,int ,V *,int (*)(),double (*)(),int (*)(),PF *);
501: void mkpfins(PF ,V *,V *);
502: void mkuf(char *,char *,NODE,SNODE,int,int,char *);
503: void newstruct(int,struct oCOMP **);
504: void optobj(Obj *);
505: void println(int, char **, int);
506: void printvars(char *,VS);
507: void resetpvs(void);
508: void searchc(char *,FUNC *);
509: void searchf(NODE,char *,FUNC *);
510: void searchpf(char *,FUNC *);
511: void searchsn(SNODE *, int, SNODE **);
512: void setbp(char *);
513: void setf(int, char **);
514: void setstruct(char *,NODE);
515: void showbp(int);
516: void showbps(void);
517: void showpos(void);
518: void simplify_ins(PFINS ,Obj *);
519: void sprintvars(char *,VS);
520: void structdef(char *,NODE);
521: void substfp(VL ,Obj ,PF ,PF ,Obj *);
522: void substfr(VL ,Obj ,PF ,PF ,Obj *);
523: void substfv(VL ,V ,PF ,PF ,Obj *);
524: void substpr(VL ,int ,Obj ,V ,Obj ,Obj *);
525: void substr(VL ,int ,Obj ,V ,Obj ,Obj *);
526: void appendtonode(NODE,pointer, NODE *);
527: void getarray(pointer,NODE,pointer *);
528: void putarray(pointer,NODE,pointer);
529:
530: void addcomp(VL,COMP,COMP,COMP *);
531: void subcomp(VL,COMP,COMP,COMP *);
532: void mulcomp(VL,COMP,COMP,COMP *);
533: void divcomp(VL,COMP,COMP,COMP *);
534: void chsgncomp(COMP,COMP *);
535: void pwrcomp(VL,COMP,Obj,COMP *);
536: int compcomp(VL,COMP,COMP);
537: #else
538: int arf_comp();
539: int complist();
540: int complist();
541: int getcompsize();
542: int getpvar();
543: int getpvar();
544: int gettype();
545: int indextotype();
546: int loadfile();
547: int loadfiles();
548: int makepvar();
549: int membertoindex();
550: int qcoefp();
551: int qcoefr();
552: int rangecheck();
553: int structtoindex();
554: pointer eval();
555: pointer evalf();
556: pointer evalif();
557: pointer evalnode();
558: pointer evalpf();
559: pointer evalparif();
560: pointer evalpv();
561: pointer evalstat();
562: void _mkpfins();
563: void appendpfins();
564: void appenduf();
565: void arf_add();
566: void arf_chsgn();
567: void arf_div();
568: void arf_init();
569: void arf_mul();
570: void arf_pwr();
571: void arf_remain();
572: void arf_sub();
573: void bp();
574: void clearbp();
575: void debug();
576: void debug_init();
577: void delbp();
578: void derivr();
579: void derivvar();
580: void duppfins();
581: void error();
582: void evalins();
583: void evalnodebody();
584: void evalp();
585: void evalr();
586: void evalv();
587: void getarrayp();
588: void getmember();
589: void getmemberp();
590: void help();
591: void instov();
592: void memberofstruct();
593: void mkpf();
594: void mkpfins();
595: void mkuf();
596: void newstruct();
597: void optobj();
598: void println();
599: void printvars();
600: void resetpvs();
601: void searchc();
602: void searchf();
603: void searchpf();
604: void searchsn();
605: void setbp();
606: void setf();
607: void setstruct();
608: void showbp();
609: void showbps();
610: void showpos();
611: void simplify_ins();
612: void sprintvars();
613: void structdef();
614: void substfp();
615: void substfr();
616: void substfv();
617: void substpr();
618: void substr();
619: void appendtonode();
620: void getarray();
621: void putarray();
622:
623: void addcomp();
624: void subcomp();
625: void mulcomp();
626: void divcomp();
627: void chsgncomp();
628: void pwrcomp();
629: int compcomp();
630: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>