Annotation of OpenXM_contrib2/asir2000/parse/parse.y, Revision 1.18
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.18 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/parse.y,v 1.17 2003/05/16 07:56:16 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.15 noro 66: extern int gdef,mgdef;
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.18 ! noro 92: %token <i> STRUCT POINT NEWSTRUCT ANS FDEF PFDEF MODDEF MODEND GLOBAL MGLOBAL LOCALF CMP OR AND CAR CDR QUOTED
1.10 noro 93: %token <i> DO WHILE FOR IF ELSE BREAK RETURN CONTINUE PARIF MAP RECMAP TIMER GF2NGEN GFPNGEN GFSNGEN GETOPT
1.1 noro 94: %token <i> FOP_AND FOP_OR FOP_IMPL FOP_REPL FOP_EQUIV FOP_NOT LOP
95: %token <p> FORMULA UCASE LCASE STR SELF BOPASS
96: %token <p> '+' '-' '*' '/' '^' '%'
97:
98: %type <p> desc rawstr
99: %type <f> expr pexpr opt
100: %type <s> stat complex
1.17 noro 101: %type <n> stats node _node pvars vars members optlist
1.1 noro 102:
103: %right '=' BOPASS
104: %right '?' ':'
105: %right FOP_NOT
106: %left FOP_EQUIV
107: %left FOP_REPL
108: %left FOP_IMPL
109: %left FOP_OR
110: %left FOP_AND
111: %left LOP
112: %left LCASE
113: %left OR
114: %left AND
115: %left '&'
116: %left CMP
117: %left '+' '-'
118: %left PLUS
119: %left MINUS
120: %left '*' '/' '%'
121: %right '^'
122: %right '!'
123: %right SELF
124: %left POINT
125:
126: %%
127:
128: start : stat
129: { parse_snode = $1; YYACCEPT; }
130: ;
131: stat : tail
132: { $$ = 0; }
133: | GLOBAL { gdef=1; } pvars { gdef=0; } tail
134: { $$ = 0; }
1.18 ! noro 135: | LOCALF vars tail
! 136: { appenduflist($2); $$ = 0; }
1.15 noro 137: | MGLOBAL { mgdef=1; } pvars { mgdef=0; } tail
138: { $$ = 0; }
1.4 noro 139: | STRUCT rawstr '{' members '}' tail
1.1 noro 140: { structdef($2,$4); $$ = 0; }
141: | expr tail
142: { $$ = mksnode(1,S_SINGLE,$1); }
143: | complex
144: { $$ = $1; }
145: | BREAK tail
146: { $$ = mksnode(0,S_BREAK); }
147: | CONTINUE tail
148: { $$ = mksnode(0,S_CONTINUE); }
149: | RETURN tail
150: { $$ = mksnode(1,S_RETURN,0); }
151: | RETURN expr tail
152: { $$ = mksnode(1,S_RETURN,$2); }
153: | IF '(' node ')' stat
154: { $$ = mksnode(4,S_IFELSE,$1,$3,$5,0); $5?$$->ln=$5->ln:0; NOPR; }
155: | IF '(' node ')' stat ELSE stat
156: { $$ = mksnode(4,S_IFELSE,$1,$3,$5,$7); $7?$$->ln=$7->ln:0; NOPR; }
157: | FOR '(' node ';' node ';' node ')' stat
158: { $$ = mksnode(5,S_FOR,$1,$3,$5?$5:ONENODE,$7,$9); $9?$$->ln=$9->ln:0; NOPR; }
159: | WHILE '(' node ')' stat
160: { $$ = mksnode(5,S_FOR,$1,0,$3,0,$5); $5?$$->ln=$5->ln:0; NOPR; }
161: | DO stat WHILE '(' node ')' tail
162: { $$ = mksnode(3,S_DO,$1,$2,$5); }
163: | LCASE '(' node ')' ':' '=' expr tail
164: { $$ = mksnode(3,S_PFDEF,$1,$3,$7); NOPR; }
165: | PFDEF LCASE '(' node ')'
166: { $$ = mksnode(3,S_PFDEF,$2,$4,0); NOPR; }
1.17 noro 167: | FDEF LCASE { mkpvs($2); } '(' node ')' desc '{' stats '}'
1.1 noro 168: {
169: mkuf($2,asir_infile->name,$5,
1.15 noro 170: mksnode(1,S_CPLX,$9),$1,asir_infile->ln,$7,CUR_MODULE);
1.1 noro 171: $$ = 0; NOPR;
1.15 noro 172: }
1.16 noro 173: | MODDEF LCASE tail
174: { CUR_MODULE = mkmodule($2); MPVS = CUR_MODULE->pvs; $$ = 0; NOPR; }
175: | MODEND tail
176: { CUR_MODULE = 0; MPVS = 0; $$ = 0; NOPR; }
1.1 noro 177: | error tail
178: { yyerrok; $$ = 0; }
179: ;
180: tail : ';'
181: { if ( main_parser ) prresult = 1; }
182: | '$'
183: { if ( main_parser ) prresult = 0; }
1.14 takayama 184: ;
1.1 noro 185: desc :
186: { $$ = 0; }
187: | STR
188: { $$ = $1; }
189: ;
190: complex : '{' stats '}'
191: { $$ = mksnode(1,S_CPLX,$2); }
192: ;
193: members : rawstr
194: { MKNODE($$,$1,0); }
195: | members ',' rawstr
196: { appendtonode($1,$3,&$$); }
197: ;
1.17 noro 198: vars : LCASE
199: { MKNODE($$,$1,0); }
200: | vars ',' LCASE
201: { appendtonode($1,$3,&$$); }
202: ;
1.1 noro 203: pvars : UCASE
204: { val = (pointer)makepvar($1); MKNODE($$,val,0); }
205: | pvars ',' UCASE
206: { appendtonode($1,(pointer)makepvar($3),&$$); }
207: ;
208: stats :
209: { $$ = 0; }
210: | stats stat
211: { appendtonode($1,(pointer)$2,&$$); }
212: ;
213: node :
214: { $$ = 0; }
215: | _node
216: { $$ = $1; }
217: ;
218: _node : expr
219: { MKNODE($$,$1,0); }
220: | _node ',' expr
221: { appendtonode($1,(pointer)$3,&$$); }
222: ;
223: optlist : opt
224: { MKNODE($$,$1,0); }
225: | optlist ',' opt
226: { appendtonode($1,(pointer)$3,&$$); }
227: ;
228: rawstr : UCASE
229: { $$ = $1; }
230: | LCASE
231: { $$ = $1; }
232: ;
233: opt : rawstr '=' expr
234: { $$ = mkfnode(2,I_OPT,$1,$3); }
235: ;
236: pexpr : STR
237: { $$ = mkfnode(1,I_STR,$1); }
238: | FORMULA
239: { $$ = mkfnode(1,I_FORMULA,$1); }
240: | ANS
241: { $$ = mkfnode(1,I_ANS,$1); }
242: | GF2NGEN
243: { $$ = mkfnode(0,I_GF2NGEN); }
244: | GFPNGEN
245: { $$ = mkfnode(0,I_GFPNGEN); }
1.10 noro 246: | GFSNGEN
247: { $$ = mkfnode(0,I_GFSNGEN); }
1.1 noro 248: | LCASE
249: {
250: FUNC f;
251:
252: searchf(noargsysf,$1,&f);
253: if ( f )
254: $$ = mkfnode(2,I_FUNC,f,0);
255: else {
256: searchc($1,&f);
257: if ( f )
258: $$ = mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,0));
259: else {
260: searchf(sysf,$1,&f);
261: if ( !f )
262: searchf(ubinf,$1,&f);
263: if ( !f )
264: searchpf($1,&f);
265: if ( !f )
266: searchf(usrf,$1,&f);
267: if ( f )
268: makesrvar(f,(P *)&val);
269: else
270: makevar($1,(P *)&val);
271: $$ = mkfnode(1,I_FORMULA,val);
272: }
273: }
274: }
275: | LCASE '(' node ')'
276: {
1.9 noro 277: gen_searchf($1,(FUNC *)&val);
1.17 noro 278: print_crossref(val);
1.1 noro 279: $$ = mkfnode(2,I_FUNC,val,mkfnode(1,I_LIST,$3));
280: }
281:
282: | LCASE '(' node '|' optlist ')'
283: {
1.9 noro 284: gen_searchf($1,(FUNC *)&val);
1.17 noro 285: print_crossref(val);
1.1 noro 286: $$ = mkfnode(3,I_FUNC_OPT,val,
287: mkfnode(1,I_LIST,$3),mkfnode(1,I_LIST,$5));
288: }
1.9 noro 289: | MAP '(' LCASE ',' node ')'
290: {
291: gen_searchf($3,(FUNC *)&val);
1.17 noro 292: print_crossref(val);
1.9 noro 293: $$ = mkfnode(2,I_MAP,val,mkfnode(1,I_LIST,$5));
294: }
295: | RECMAP '(' LCASE ',' node ')'
296: {
297: gen_searchf($3,(FUNC *)&val);
1.17 noro 298: print_crossref(val);
1.9 noro 299: $$ = mkfnode(2,I_RECMAP,val,mkfnode(1,I_LIST,$5));
300: }
1.1 noro 301: | LCASE '{' node '}' '(' node ')'
302: {
303: searchpf($1,(FUNC *)&val);
304: $$ = mkfnode(2,I_PFDERIV,val,mkfnode(1,I_LIST,$6),mkfnode(1,I_LIST,$3));
305: }
306: | GETOPT '(' rawstr ')'
307: {
308: $$ = mkfnode(2,I_GETOPT,$3);
309: }
1.9 noro 310: | GETOPT '(' ')'
1.1 noro 311: {
1.9 noro 312: $$ = mkfnode(2,I_GETOPT,0);
1.1 noro 313: }
314: | TIMER '(' expr ',' expr ',' expr ')'
315: {
316: $$ = mkfnode(3,I_TIMER,$3,$5,$7);
1.12 noro 317: }
318: | PARIF '(' LCASE ')'
319: {
320: searchf(parif,$3,(FUNC *)&val);
321: if ( !val )
322: mkparif($3,(FUNC *)&val);
323: $$ = mkfnode(2,I_FUNC,val,0);
1.1 noro 324: }
325: | PARIF '(' LCASE ',' node ')'
326: {
327: searchf(parif,$3,(FUNC *)&val);
328: if ( !val )
329: mkparif($3,(FUNC *)&val);
330: $$ = mkfnode(2,I_FUNC,val,mkfnode(1,I_LIST,$5));
331: }
332: | '(' '*' expr ')' '(' node ')'
333: {
334: $$ = mkfnode(2,I_IFUNC,$3,mkfnode(1,I_LIST,$6));
335: }
336: | CAR '(' expr ')'
337: { $$ = mkfnode(1,I_CAR,$3); }
338: | CDR '(' expr ')'
339: { $$ = mkfnode(1,I_CDR,$3); }
340: | '(' expr ')'
1.8 noro 341: { $$ = mkfnode(1,I_PAREN,$2); }
1.1 noro 342: | UCASE
343: {
1.13 noro 344: if ( main_parser || allow_create_var )
1.1 noro 345: $$ = mkfnode(2,I_PVAR,makepvar($1),0);
346: else {
347: ind = searchpvar($1);
348: if ( ind == -1 ) {
349: fprintf(stderr,"%s : no such variable.\n",$1);
350: YYABORT;
351: } else
352: $$ = mkfnode(2,I_PVAR,ind,0);
353: }
354: }
355: | pexpr '[' expr ']'
356: {
357: if ( $1->id == I_PVAR || $1->id == I_INDEX ) {
358: appendtonode((NODE)$1->arg[1],(pointer)$3,&a);
359: $1->arg[1] = (pointer)a; $$ = $1;
360: } else {
361: MKNODE(a,$3,0);
362: $$ = mkfnode(2,I_INDEX,(pointer)$1,a);
363: }
364: }
365: | pexpr POINT rawstr
1.4 noro 366: { $$ = mkfnode(2,I_POINT,$1,$3); }
1.1 noro 367: ;
368: expr : pexpr
369: { $$ = $1; }
370: | '(' STRUCT rawstr ')' pexpr
371: { $$ = mkfnode(3,I_CAST,structtoindex($3),$5,0); }
372: | expr '=' expr
373: { $$ = mkfnode(2,I_ASSPVAR,$1,$3); }
374: | expr BOPASS expr
375: { $$ = mkfnode(2,I_ASSPVAR,$1,mkfnode(3,I_BOP,$2,$1,$3)); }
376: | expr SELF
377: { $$ = mkfnode(2,I_POSTSELF,$2,$1); }
378: | SELF expr
379: { $$ = mkfnode(2,I_PRESELF,$1,$2); }
380: | '[' node ']'
381: { $$ = mkfnode(1,I_LIST,$2); }
382: | '+' expr %prec PLUS
383: { $$ = $2; }
384: | '-' expr %prec MINUS
1.11 noro 385: { $$ = mkfnode(1,I_MINUS,$2); }
1.1 noro 386: | expr '+' expr
387: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
388: | expr '-' expr
389: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
390: | expr '*' expr
391: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
392: | expr '/' expr
393: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
394: | expr '%' expr
395: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
396: | expr '^' expr
397: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
398: | expr CMP expr
399: { $$ = mkfnode(3,I_COP,$2,$1,$3); }
400: | '!' expr
401: { $$ = mkfnode(1,I_NOT,$2); }
402: | expr OR expr
403: { $$ = mkfnode(2,I_OR,$1,$3); }
404: | expr AND expr
405: { $$ = mkfnode(2,I_AND,$1,$3); }
406: | FOP_NOT expr
407: { $$ = mkfnode(3,I_LOP,$1,$2,0); }
408: | expr FOP_AND expr
409: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
410: | expr FOP_OR expr
411: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
412: | expr FOP_IMPL expr
413: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
414: | expr FOP_REPL expr
415: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
416: | expr FOP_EQUIV expr
417: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
418: | expr LOP expr
419: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
420: | expr '?' expr ':' expr
421: { $$ = mkfnode(3,I_CE,$1,$3,$5); }
422: | '<' node '>'
423: { $$ = mkfnode(1,I_EV,$2); }
424: | NEWSTRUCT '(' rawstr ')'
425: { $$ = mkfnode(1,I_NEWCOMP,(int)structtoindex($3)); }
1.6 noro 426: | QUOTED '(' expr ')'
427: { MKQUOTE(quote,$3); $$ = mkfnode(1,I_FORMULA,(pointer)quote); }
1.1 noro 428: ;
429: %%
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>