Annotation of OpenXM_contrib2/asir2000/parse/parse.y, Revision 1.3
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.3 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/parse.y,v 1.2 2000/08/21 08:31:47 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(THINK_C)
56: #define alloca(x) GC_malloc(x)
57: #endif
58: #if defined(TOWNS)
59: #include <alloca.h>
60: #endif
61: #include <ctype.h>
62: #include "ca.h"
63: #if !defined(THINK_C)
64: #include <sys/types.h>
65: #include <sys/stat.h>
66: #endif
67: #include "parse.h"
68:
69: #define NOPR (prresult=0)
70:
71: extern int gdef;
72: extern SNODE parse_snode;
73: extern int main_parser;
74:
75: int prresult;
76:
77: static int ind;
78: static FNODE t;
79: static NODE a,b;
80: static NODE2 a2;
81: static pointer val;
82: extern jmp_buf env;
83: %}
84:
85: %start start
86:
87: %union {
88: FNODE f;
89: SNODE s;
90: NODE n;
91: NODE2 n2;
92: int i;
93: pointer p;
94: }
95:
96: %token <i> STRUCT POINT NEWSTRUCT ANS FDEF PFDEF GLOBAL CMP OR AND CAR CDR
97: %token <i> DO WHILE FOR IF ELSE BREAK RETURN CONTINUE PARIF MAP TIMER GF2NGEN GFPNGEN GETOPT
98: %token <i> FOP_AND FOP_OR FOP_IMPL FOP_REPL FOP_EQUIV FOP_NOT LOP
99: %token <p> FORMULA UCASE LCASE STR SELF BOPASS
100: %token <p> '+' '-' '*' '/' '^' '%'
101:
102: %type <p> desc rawstr
103: %type <f> expr pexpr opt
104: %type <s> stat complex
105: %type <n> stats node _node pvars fields members optlist
106:
107: %right '=' BOPASS
108: %right '?' ':'
109: %right FOP_NOT
110: %left FOP_EQUIV
111: %left FOP_REPL
112: %left FOP_IMPL
113: %left FOP_OR
114: %left FOP_AND
115: %left LOP
116: %left LCASE
117: %left OR
118: %left AND
119: %left '&'
120: %left CMP
121: %left '+' '-'
122: %left PLUS
123: %left MINUS
124: %left '*' '/' '%'
125: %right '^'
126: %right '!'
127: %right SELF
128: %left POINT
129:
130: %%
131:
132: start : stat
133: { parse_snode = $1; YYACCEPT; }
134: ;
135: stat : tail
136: { $$ = 0; }
137: | GLOBAL { gdef=1; } pvars { gdef=0; } tail
138: { $$ = 0; }
139: | STRUCT rawstr '{' fields '}' tail
140: { structdef($2,$4); $$ = 0; }
141: | STRUCT rawstr '{' fields '}' pvars tail
142: { structdef($2,$4); setstruct($2,$6); $$ = 0; }
143: | STRUCT rawstr pvars tail
144: { setstruct($2,$3); $$ = 0; }
145: | expr tail
146: { $$ = mksnode(1,S_SINGLE,$1); }
147: | complex
148: { $$ = $1; }
149: | BREAK tail
150: { $$ = mksnode(0,S_BREAK); }
151: | CONTINUE tail
152: { $$ = mksnode(0,S_CONTINUE); }
153: | RETURN tail
154: { $$ = mksnode(1,S_RETURN,0); }
155: | RETURN expr tail
156: { $$ = mksnode(1,S_RETURN,$2); }
157: | IF '(' node ')' stat
158: { $$ = mksnode(4,S_IFELSE,$1,$3,$5,0); $5?$$->ln=$5->ln:0; NOPR; }
159: | IF '(' node ')' stat ELSE stat
160: { $$ = mksnode(4,S_IFELSE,$1,$3,$5,$7); $7?$$->ln=$7->ln:0; NOPR; }
161: | FOR '(' node ';' node ';' node ')' stat
162: { $$ = mksnode(5,S_FOR,$1,$3,$5?$5:ONENODE,$7,$9); $9?$$->ln=$9->ln:0; NOPR; }
163: | WHILE '(' node ')' stat
164: { $$ = mksnode(5,S_FOR,$1,0,$3,0,$5); $5?$$->ln=$5->ln:0; NOPR; }
165: | DO stat WHILE '(' node ')' tail
166: { $$ = mksnode(3,S_DO,$1,$2,$5); }
167: | LCASE '(' node ')' ':' '=' expr tail
168: { $$ = mksnode(3,S_PFDEF,$1,$3,$7); NOPR; }
169: | PFDEF LCASE '(' node ')'
170: { $$ = mksnode(3,S_PFDEF,$2,$4,0); NOPR; }
171: | FDEF LCASE { mkpvs(); } '(' node ')' desc '{' stats '}'
172: {
173: mkuf($2,asir_infile->name,$5,
174: mksnode(1,S_CPLX,$9),$1,asir_infile->ln,$7);
175: $$ = 0; NOPR;
176: }
177: | error tail
178: { yyerrok; $$ = 0; }
179: ;
180: tail : ';'
181: { if ( main_parser ) prresult = 1; }
182: | '$'
183: { if ( main_parser ) prresult = 0; }
184: desc :
185: { $$ = 0; }
186: | STR
187: { $$ = $1; }
188: ;
189: complex : '{' stats '}'
190: { $$ = mksnode(1,S_CPLX,$2); }
191: ;
192: fields :
193: { $$ = 0; }
194: | fields members tail
195: { MKNODE(a,0,$2); appendtonode($1,(pointer)a,&$$); }
196: | fields STRUCT rawstr members tail
197: { MKNODE(a,$3,$4); appendtonode($1,(pointer)a,&$$); }
198: ;
199: members : rawstr
200: { MKNODE($$,$1,0); }
201: | members ',' rawstr
202: { appendtonode($1,$3,&$$); }
203: ;
204: pvars : UCASE
205: { val = (pointer)makepvar($1); MKNODE($$,val,0); }
206: | pvars ',' UCASE
207: { appendtonode($1,(pointer)makepvar($3),&$$); }
208: ;
209: stats :
210: { $$ = 0; }
211: | stats stat
212: { appendtonode($1,(pointer)$2,&$$); }
213: ;
214: node :
215: { $$ = 0; }
216: | _node
217: { $$ = $1; }
218: ;
219: _node : expr
220: { MKNODE($$,$1,0); }
221: | _node ',' expr
222: { appendtonode($1,(pointer)$3,&$$); }
223: ;
224: optlist : opt
225: { MKNODE($$,$1,0); }
226: | optlist ',' opt
227: { appendtonode($1,(pointer)$3,&$$); }
228: ;
229: rawstr : UCASE
230: { $$ = $1; }
231: | LCASE
232: { $$ = $1; }
233: ;
234: opt : rawstr '=' expr
235: { $$ = mkfnode(2,I_OPT,$1,$3); }
236: ;
237: pexpr : STR
238: { $$ = mkfnode(1,I_STR,$1); }
239: | FORMULA
240: { $$ = mkfnode(1,I_FORMULA,$1); }
241: | ANS
242: { $$ = mkfnode(1,I_ANS,$1); }
243: | GF2NGEN
244: { $$ = mkfnode(0,I_GF2NGEN); }
245: | GFPNGEN
246: { $$ = mkfnode(0,I_GFPNGEN); }
247: | LCASE
248: {
249: FUNC f;
250:
251: searchf(noargsysf,$1,&f);
252: if ( f )
253: $$ = mkfnode(2,I_FUNC,f,0);
254: else {
255: searchc($1,&f);
256: if ( f )
257: $$ = mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,0));
258: else {
259: searchf(sysf,$1,&f);
260: if ( !f )
261: searchf(ubinf,$1,&f);
262: if ( !f )
263: searchpf($1,&f);
264: if ( !f )
265: searchf(usrf,$1,&f);
266: if ( f )
267: makesrvar(f,(P *)&val);
268: else
269: makevar($1,(P *)&val);
270: $$ = mkfnode(1,I_FORMULA,val);
271: }
272: }
273: }
274: | LCASE '(' node ')'
275: {
276: searchf(sysf,$1,(FUNC *)&val);
277: if ( !val )
278: searchf(ubinf,$1,(FUNC *)&val);
279: if ( !val )
280: searchpf($1,(FUNC *)&val);
281: if ( !val )
282: searchf(usrf,$1,(FUNC *)&val);
283: if ( !val )
284: appenduf($1,(FUNC *)&val);
285: $$ = mkfnode(2,I_FUNC,val,mkfnode(1,I_LIST,$3));
286: }
287:
288: | LCASE '(' node '|' optlist ')'
289: {
290: searchf(sysf,$1,(FUNC *)&val);
291: if ( !val )
292: searchf(ubinf,$1,(FUNC *)&val);
293: if ( !val )
294: searchpf($1,(FUNC *)&val);
295: if ( !val )
296: searchf(usrf,$1,(FUNC *)&val);
297: if ( !val )
298: appenduf($1,(FUNC *)&val);
299: $$ = mkfnode(3,I_FUNC_OPT,val,
300: mkfnode(1,I_LIST,$3),mkfnode(1,I_LIST,$5));
301: }
302: | LCASE '{' node '}' '(' node ')'
303: {
304: searchpf($1,(FUNC *)&val);
305: $$ = mkfnode(2,I_PFDERIV,val,mkfnode(1,I_LIST,$6),mkfnode(1,I_LIST,$3));
306: }
307: | GETOPT '(' rawstr ')'
308: {
309: $$ = mkfnode(2,I_GETOPT,$3);
310: }
311: | MAP '(' LCASE ',' node ')'
312: {
313: searchf(sysf,$3,(FUNC *)&val);
314: if ( !val )
315: searchf(ubinf,$3,(FUNC *)&val);
316: if ( !val )
317: searchpf($3,(FUNC *)&val);
318: if ( !val )
319: searchf(usrf,$3,(FUNC *)&val);
320: if ( !val )
321: appenduf($3,(FUNC *)&val);
322: $$ = mkfnode(2,I_MAP,val,mkfnode(1,I_LIST,$5));
323: }
324: | TIMER '(' expr ',' expr ',' expr ')'
325: {
326: $$ = mkfnode(3,I_TIMER,$3,$5,$7);
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 ')'
344: { $$ = $2; }
345: | UCASE
346: {
347: if ( main_parser )
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
369: { memberofstruct($1,$3,&$$); }
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
388: { $$ = mkfnode(3,I_BOP,$1,0,$2); }
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)); }
429: ;
430: %%
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>