Annotation of OpenXM_contrib2/asir2000/parse/parse.y, Revision 1.19
1.2 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.19 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/parse.y,v 1.18 2003/05/16 09:34:50 noro Exp $
1.2 noro 49: */
1.1 noro 50: %{
51: #define malloc(x) GC_malloc(x)
52: #define realloc(x,y) GC_realloc(x,y)
53: #define free(x) GC_free(x)
54:
55: #if defined(TOWNS)
56: #include <alloca.h>
57: #endif
58: #include <ctype.h>
59: #include "ca.h"
60: #include <sys/types.h>
61: #include <sys/stat.h>
62: #include "parse.h"
63:
64: #define NOPR (prresult=0)
65:
1.19 ! noro 66: extern int gdef,mgdef,ldef;
1.1 noro 67: extern SNODE parse_snode;
1.13 noro 68: extern int main_parser, allow_create_var;
1.1 noro 69:
70: int prresult;
71:
72: static int ind;
73: static FNODE t;
74: static NODE a,b;
75: static NODE2 a2;
76: static pointer val;
1.6 noro 77: static QUOTE quote;
1.1 noro 78: extern jmp_buf env;
79: %}
80:
81: %start start
82:
83: %union {
84: FNODE f;
85: SNODE s;
86: NODE n;
87: NODE2 n2;
88: int i;
89: pointer p;
90: }
91:
1.19 ! noro 92: %token <i> STRUCT POINT NEWSTRUCT ANS FDEF PFDEF MODDEF MODEND
! 93: %token <i> GLOBAL MGLOBAL LOCAL LOCALF CMP OR AND CAR CDR QUOTED
1.10 noro 94: %token <i> DO WHILE FOR IF ELSE BREAK RETURN CONTINUE PARIF MAP RECMAP TIMER GF2NGEN GFPNGEN GFSNGEN GETOPT
1.1 noro 95: %token <i> FOP_AND FOP_OR FOP_IMPL FOP_REPL FOP_EQUIV FOP_NOT LOP
96: %token <p> FORMULA UCASE LCASE STR SELF BOPASS
97: %token <p> '+' '-' '*' '/' '^' '%'
98:
99: %type <p> desc rawstr
100: %type <f> expr pexpr opt
101: %type <s> stat complex
1.17 noro 102: %type <n> stats node _node pvars vars members optlist
1.1 noro 103:
104: %right '=' BOPASS
105: %right '?' ':'
106: %right FOP_NOT
107: %left FOP_EQUIV
108: %left FOP_REPL
109: %left FOP_IMPL
110: %left FOP_OR
111: %left FOP_AND
112: %left LOP
113: %left LCASE
114: %left OR
115: %left AND
116: %left '&'
117: %left CMP
118: %left '+' '-'
119: %left PLUS
120: %left MINUS
121: %left '*' '/' '%'
122: %right '^'
123: %right '!'
124: %right SELF
125: %left POINT
126:
127: %%
128:
129: start : stat
130: { parse_snode = $1; YYACCEPT; }
131: ;
132: stat : tail
133: { $$ = 0; }
134: | GLOBAL { gdef=1; } pvars { gdef=0; } tail
1.19 ! noro 135: { $$ = 0; NOPR; }
! 136: | MGLOBAL { mgdef=1; } pvars { mgdef=0; } tail
! 137: { $$ = 0; NOPR; }
! 138: | LOCAL { ldef=1; } pvars { ldef=0; } tail
! 139: { $$ = 0; NOPR; }
1.18 noro 140: | LOCALF vars tail
1.19 ! noro 141: { appenduflist($2); $$ = 0; NOPR; }
1.4 noro 142: | STRUCT rawstr '{' members '}' tail
1.19 ! noro 143: { structdef($2,$4); $$ = 0; NOPR; }
1.1 noro 144: | expr tail
145: { $$ = mksnode(1,S_SINGLE,$1); }
146: | complex
147: { $$ = $1; }
148: | BREAK tail
149: { $$ = mksnode(0,S_BREAK); }
150: | CONTINUE tail
151: { $$ = mksnode(0,S_CONTINUE); }
152: | RETURN tail
153: { $$ = mksnode(1,S_RETURN,0); }
154: | RETURN expr tail
155: { $$ = mksnode(1,S_RETURN,$2); }
156: | IF '(' node ')' stat
157: { $$ = mksnode(4,S_IFELSE,$1,$3,$5,0); $5?$$->ln=$5->ln:0; NOPR; }
158: | IF '(' node ')' stat ELSE stat
159: { $$ = mksnode(4,S_IFELSE,$1,$3,$5,$7); $7?$$->ln=$7->ln:0; NOPR; }
160: | FOR '(' node ';' node ';' node ')' stat
161: { $$ = mksnode(5,S_FOR,$1,$3,$5?$5:ONENODE,$7,$9); $9?$$->ln=$9->ln:0; NOPR; }
162: | WHILE '(' node ')' stat
163: { $$ = mksnode(5,S_FOR,$1,0,$3,0,$5); $5?$$->ln=$5->ln:0; NOPR; }
164: | DO stat WHILE '(' node ')' tail
165: { $$ = mksnode(3,S_DO,$1,$2,$5); }
166: | LCASE '(' node ')' ':' '=' expr tail
167: { $$ = mksnode(3,S_PFDEF,$1,$3,$7); NOPR; }
168: | PFDEF LCASE '(' node ')'
169: { $$ = mksnode(3,S_PFDEF,$2,$4,0); NOPR; }
1.19 ! noro 170: | FDEF LCASE { mkpvs($2); } '(' { ldef = 1; } node { ldef = -1; } ')' desc '{' stats '}'
1.1 noro 171: {
1.19 ! noro 172: mkuf($2,asir_infile->name,$6,
! 173: mksnode(1,S_CPLX,$11),$1,asir_infile->ln,$9,CUR_MODULE);
1.1 noro 174: $$ = 0; NOPR;
1.15 noro 175: }
1.16 noro 176: | MODDEF LCASE tail
177: { CUR_MODULE = mkmodule($2); MPVS = CUR_MODULE->pvs; $$ = 0; NOPR; }
178: | MODEND tail
179: { CUR_MODULE = 0; MPVS = 0; $$ = 0; NOPR; }
1.1 noro 180: | error tail
181: { yyerrok; $$ = 0; }
182: ;
183: tail : ';'
184: { if ( main_parser ) prresult = 1; }
185: | '$'
186: { if ( main_parser ) prresult = 0; }
1.14 takayama 187: ;
1.1 noro 188: desc :
189: { $$ = 0; }
190: | STR
191: { $$ = $1; }
192: ;
193: complex : '{' stats '}'
194: { $$ = mksnode(1,S_CPLX,$2); }
195: ;
196: members : rawstr
197: { MKNODE($$,$1,0); }
198: | members ',' rawstr
199: { appendtonode($1,$3,&$$); }
200: ;
1.17 noro 201: vars : LCASE
202: { MKNODE($$,$1,0); }
203: | vars ',' LCASE
204: { appendtonode($1,$3,&$$); }
205: ;
1.1 noro 206: pvars : UCASE
207: { val = (pointer)makepvar($1); MKNODE($$,val,0); }
208: | pvars ',' UCASE
209: { appendtonode($1,(pointer)makepvar($3),&$$); }
210: ;
211: stats :
212: { $$ = 0; }
213: | stats stat
214: { appendtonode($1,(pointer)$2,&$$); }
215: ;
216: node :
217: { $$ = 0; }
218: | _node
219: { $$ = $1; }
220: ;
221: _node : expr
222: { MKNODE($$,$1,0); }
223: | _node ',' expr
224: { appendtonode($1,(pointer)$3,&$$); }
225: ;
226: optlist : opt
227: { MKNODE($$,$1,0); }
228: | optlist ',' opt
229: { appendtonode($1,(pointer)$3,&$$); }
230: ;
231: rawstr : UCASE
232: { $$ = $1; }
233: | LCASE
234: { $$ = $1; }
235: ;
236: opt : rawstr '=' expr
237: { $$ = mkfnode(2,I_OPT,$1,$3); }
238: ;
239: pexpr : STR
240: { $$ = mkfnode(1,I_STR,$1); }
241: | FORMULA
242: { $$ = mkfnode(1,I_FORMULA,$1); }
243: | ANS
244: { $$ = mkfnode(1,I_ANS,$1); }
245: | GF2NGEN
246: { $$ = mkfnode(0,I_GF2NGEN); }
247: | GFPNGEN
248: { $$ = mkfnode(0,I_GFPNGEN); }
1.10 noro 249: | GFSNGEN
250: { $$ = mkfnode(0,I_GFSNGEN); }
1.1 noro 251: | LCASE
252: {
253: FUNC f;
254:
255: searchf(noargsysf,$1,&f);
256: if ( f )
257: $$ = mkfnode(2,I_FUNC,f,0);
258: else {
259: searchc($1,&f);
260: if ( f )
261: $$ = mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,0));
262: else {
263: searchf(sysf,$1,&f);
264: if ( !f )
265: searchf(ubinf,$1,&f);
266: if ( !f )
267: searchpf($1,&f);
268: if ( !f )
269: searchf(usrf,$1,&f);
270: if ( f )
271: makesrvar(f,(P *)&val);
272: else
273: makevar($1,(P *)&val);
274: $$ = mkfnode(1,I_FORMULA,val);
275: }
276: }
277: }
278: | LCASE '(' node ')'
279: {
1.9 noro 280: gen_searchf($1,(FUNC *)&val);
1.17 noro 281: print_crossref(val);
1.1 noro 282: $$ = mkfnode(2,I_FUNC,val,mkfnode(1,I_LIST,$3));
283: }
284:
285: | LCASE '(' node '|' optlist ')'
286: {
1.9 noro 287: gen_searchf($1,(FUNC *)&val);
1.17 noro 288: print_crossref(val);
1.1 noro 289: $$ = mkfnode(3,I_FUNC_OPT,val,
290: mkfnode(1,I_LIST,$3),mkfnode(1,I_LIST,$5));
291: }
1.9 noro 292: | MAP '(' LCASE ',' node ')'
293: {
294: gen_searchf($3,(FUNC *)&val);
1.17 noro 295: print_crossref(val);
1.9 noro 296: $$ = mkfnode(2,I_MAP,val,mkfnode(1,I_LIST,$5));
297: }
298: | RECMAP '(' LCASE ',' node ')'
299: {
300: gen_searchf($3,(FUNC *)&val);
1.17 noro 301: print_crossref(val);
1.9 noro 302: $$ = mkfnode(2,I_RECMAP,val,mkfnode(1,I_LIST,$5));
303: }
1.1 noro 304: | LCASE '{' node '}' '(' node ')'
305: {
306: searchpf($1,(FUNC *)&val);
307: $$ = mkfnode(2,I_PFDERIV,val,mkfnode(1,I_LIST,$6),mkfnode(1,I_LIST,$3));
308: }
309: | GETOPT '(' rawstr ')'
310: {
311: $$ = mkfnode(2,I_GETOPT,$3);
312: }
1.9 noro 313: | GETOPT '(' ')'
1.1 noro 314: {
1.9 noro 315: $$ = mkfnode(2,I_GETOPT,0);
1.1 noro 316: }
317: | TIMER '(' expr ',' expr ',' expr ')'
318: {
319: $$ = mkfnode(3,I_TIMER,$3,$5,$7);
1.12 noro 320: }
321: | PARIF '(' LCASE ')'
322: {
323: searchf(parif,$3,(FUNC *)&val);
324: if ( !val )
325: mkparif($3,(FUNC *)&val);
326: $$ = mkfnode(2,I_FUNC,val,0);
1.1 noro 327: }
328: | PARIF '(' LCASE ',' node ')'
329: {
330: searchf(parif,$3,(FUNC *)&val);
331: if ( !val )
332: mkparif($3,(FUNC *)&val);
333: $$ = mkfnode(2,I_FUNC,val,mkfnode(1,I_LIST,$5));
334: }
335: | '(' '*' expr ')' '(' node ')'
336: {
337: $$ = mkfnode(2,I_IFUNC,$3,mkfnode(1,I_LIST,$6));
338: }
339: | CAR '(' expr ')'
340: { $$ = mkfnode(1,I_CAR,$3); }
341: | CDR '(' expr ')'
342: { $$ = mkfnode(1,I_CDR,$3); }
343: | '(' expr ')'
1.8 noro 344: { $$ = mkfnode(1,I_PAREN,$2); }
1.1 noro 345: | UCASE
346: {
1.13 noro 347: if ( main_parser || allow_create_var )
1.1 noro 348: $$ = mkfnode(2,I_PVAR,makepvar($1),0);
349: else {
350: ind = searchpvar($1);
351: if ( ind == -1 ) {
352: fprintf(stderr,"%s : no such variable.\n",$1);
353: YYABORT;
354: } else
355: $$ = mkfnode(2,I_PVAR,ind,0);
356: }
357: }
358: | pexpr '[' expr ']'
359: {
360: if ( $1->id == I_PVAR || $1->id == I_INDEX ) {
361: appendtonode((NODE)$1->arg[1],(pointer)$3,&a);
362: $1->arg[1] = (pointer)a; $$ = $1;
363: } else {
364: MKNODE(a,$3,0);
365: $$ = mkfnode(2,I_INDEX,(pointer)$1,a);
366: }
367: }
368: | pexpr POINT rawstr
1.4 noro 369: { $$ = mkfnode(2,I_POINT,$1,$3); }
1.1 noro 370: ;
371: expr : pexpr
372: { $$ = $1; }
373: | '(' STRUCT rawstr ')' pexpr
374: { $$ = mkfnode(3,I_CAST,structtoindex($3),$5,0); }
375: | expr '=' expr
376: { $$ = mkfnode(2,I_ASSPVAR,$1,$3); }
377: | expr BOPASS expr
378: { $$ = mkfnode(2,I_ASSPVAR,$1,mkfnode(3,I_BOP,$2,$1,$3)); }
379: | expr SELF
380: { $$ = mkfnode(2,I_POSTSELF,$2,$1); }
381: | SELF expr
382: { $$ = mkfnode(2,I_PRESELF,$1,$2); }
383: | '[' node ']'
384: { $$ = mkfnode(1,I_LIST,$2); }
385: | '+' expr %prec PLUS
386: { $$ = $2; }
387: | '-' expr %prec MINUS
1.11 noro 388: { $$ = mkfnode(1,I_MINUS,$2); }
1.1 noro 389: | expr '+' expr
390: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
391: | expr '-' expr
392: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
393: | expr '*' expr
394: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
395: | expr '/' expr
396: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
397: | expr '%' expr
398: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
399: | expr '^' expr
400: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
401: | expr CMP expr
402: { $$ = mkfnode(3,I_COP,$2,$1,$3); }
403: | '!' expr
404: { $$ = mkfnode(1,I_NOT,$2); }
405: | expr OR expr
406: { $$ = mkfnode(2,I_OR,$1,$3); }
407: | expr AND expr
408: { $$ = mkfnode(2,I_AND,$1,$3); }
409: | FOP_NOT expr
410: { $$ = mkfnode(3,I_LOP,$1,$2,0); }
411: | expr FOP_AND expr
412: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
413: | expr FOP_OR expr
414: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
415: | expr FOP_IMPL expr
416: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
417: | expr FOP_REPL expr
418: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
419: | expr FOP_EQUIV expr
420: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
421: | expr LOP expr
422: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
423: | expr '?' expr ':' expr
424: { $$ = mkfnode(3,I_CE,$1,$3,$5); }
425: | '<' node '>'
426: { $$ = mkfnode(1,I_EV,$2); }
427: | NEWSTRUCT '(' rawstr ')'
428: { $$ = mkfnode(1,I_NEWCOMP,(int)structtoindex($3)); }
1.6 noro 429: | QUOTED '(' expr ')'
430: { MKQUOTE(quote,$3); $$ = mkfnode(1,I_FORMULA,(pointer)quote); }
1.1 noro 431: ;
432: %%
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>