Annotation of OpenXM_contrib2/asir2000/parse/parse.y, Revision 1.4
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.4 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/parse.y,v 1.3 2000/08/22 05:04:27 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
1.4 ! noro 105: %type <n> stats node _node pvars members optlist
1.1 noro 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; }
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; }
167: | FDEF LCASE { mkpvs(); } '(' node ')' desc '{' stats '}'
168: {
169: mkuf($2,asir_infile->name,$5,
170: mksnode(1,S_CPLX,$9),$1,asir_infile->ln,$7);
171: $$ = 0; NOPR;
172: }
173: | error tail
174: { yyerrok; $$ = 0; }
175: ;
176: tail : ';'
177: { if ( main_parser ) prresult = 1; }
178: | '$'
179: { if ( main_parser ) prresult = 0; }
180: desc :
181: { $$ = 0; }
182: | STR
183: { $$ = $1; }
184: ;
185: complex : '{' stats '}'
186: { $$ = mksnode(1,S_CPLX,$2); }
187: ;
188: members : rawstr
189: { MKNODE($$,$1,0); }
190: | members ',' rawstr
191: { appendtonode($1,$3,&$$); }
192: ;
193: pvars : UCASE
194: { val = (pointer)makepvar($1); MKNODE($$,val,0); }
195: | pvars ',' UCASE
196: { appendtonode($1,(pointer)makepvar($3),&$$); }
197: ;
198: stats :
199: { $$ = 0; }
200: | stats stat
201: { appendtonode($1,(pointer)$2,&$$); }
202: ;
203: node :
204: { $$ = 0; }
205: | _node
206: { $$ = $1; }
207: ;
208: _node : expr
209: { MKNODE($$,$1,0); }
210: | _node ',' expr
211: { appendtonode($1,(pointer)$3,&$$); }
212: ;
213: optlist : opt
214: { MKNODE($$,$1,0); }
215: | optlist ',' opt
216: { appendtonode($1,(pointer)$3,&$$); }
217: ;
218: rawstr : UCASE
219: { $$ = $1; }
220: | LCASE
221: { $$ = $1; }
222: ;
223: opt : rawstr '=' expr
224: { $$ = mkfnode(2,I_OPT,$1,$3); }
225: ;
226: pexpr : STR
227: { $$ = mkfnode(1,I_STR,$1); }
228: | FORMULA
229: { $$ = mkfnode(1,I_FORMULA,$1); }
230: | ANS
231: { $$ = mkfnode(1,I_ANS,$1); }
232: | GF2NGEN
233: { $$ = mkfnode(0,I_GF2NGEN); }
234: | GFPNGEN
235: { $$ = mkfnode(0,I_GFPNGEN); }
236: | LCASE
237: {
238: FUNC f;
239:
240: searchf(noargsysf,$1,&f);
241: if ( f )
242: $$ = mkfnode(2,I_FUNC,f,0);
243: else {
244: searchc($1,&f);
245: if ( f )
246: $$ = mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,0));
247: else {
248: searchf(sysf,$1,&f);
249: if ( !f )
250: searchf(ubinf,$1,&f);
251: if ( !f )
252: searchpf($1,&f);
253: if ( !f )
254: searchf(usrf,$1,&f);
255: if ( f )
256: makesrvar(f,(P *)&val);
257: else
258: makevar($1,(P *)&val);
259: $$ = mkfnode(1,I_FORMULA,val);
260: }
261: }
262: }
263: | LCASE '(' node ')'
264: {
265: searchf(sysf,$1,(FUNC *)&val);
266: if ( !val )
267: searchf(ubinf,$1,(FUNC *)&val);
268: if ( !val )
269: searchpf($1,(FUNC *)&val);
270: if ( !val )
271: searchf(usrf,$1,(FUNC *)&val);
272: if ( !val )
273: appenduf($1,(FUNC *)&val);
274: $$ = mkfnode(2,I_FUNC,val,mkfnode(1,I_LIST,$3));
275: }
276:
277: | LCASE '(' node '|' optlist ')'
278: {
279: searchf(sysf,$1,(FUNC *)&val);
280: if ( !val )
281: searchf(ubinf,$1,(FUNC *)&val);
282: if ( !val )
283: searchpf($1,(FUNC *)&val);
284: if ( !val )
285: searchf(usrf,$1,(FUNC *)&val);
286: if ( !val )
287: appenduf($1,(FUNC *)&val);
288: $$ = mkfnode(3,I_FUNC_OPT,val,
289: mkfnode(1,I_LIST,$3),mkfnode(1,I_LIST,$5));
290: }
291: | LCASE '{' node '}' '(' node ')'
292: {
293: searchpf($1,(FUNC *)&val);
294: $$ = mkfnode(2,I_PFDERIV,val,mkfnode(1,I_LIST,$6),mkfnode(1,I_LIST,$3));
295: }
296: | GETOPT '(' rawstr ')'
297: {
298: $$ = mkfnode(2,I_GETOPT,$3);
299: }
300: | MAP '(' LCASE ',' node ')'
301: {
302: searchf(sysf,$3,(FUNC *)&val);
303: if ( !val )
304: searchf(ubinf,$3,(FUNC *)&val);
305: if ( !val )
306: searchpf($3,(FUNC *)&val);
307: if ( !val )
308: searchf(usrf,$3,(FUNC *)&val);
309: if ( !val )
310: appenduf($3,(FUNC *)&val);
311: $$ = mkfnode(2,I_MAP,val,mkfnode(1,I_LIST,$5));
312: }
313: | TIMER '(' expr ',' expr ',' expr ')'
314: {
315: $$ = mkfnode(3,I_TIMER,$3,$5,$7);
316: }
317: | PARIF '(' LCASE ',' node ')'
318: {
319: searchf(parif,$3,(FUNC *)&val);
320: if ( !val )
321: mkparif($3,(FUNC *)&val);
322: $$ = mkfnode(2,I_FUNC,val,mkfnode(1,I_LIST,$5));
323: }
324: | '(' '*' expr ')' '(' node ')'
325: {
326: $$ = mkfnode(2,I_IFUNC,$3,mkfnode(1,I_LIST,$6));
327: }
328: | CAR '(' expr ')'
329: { $$ = mkfnode(1,I_CAR,$3); }
330: | CDR '(' expr ')'
331: { $$ = mkfnode(1,I_CDR,$3); }
332: | '(' expr ')'
333: { $$ = $2; }
334: | UCASE
335: {
336: if ( main_parser )
337: $$ = mkfnode(2,I_PVAR,makepvar($1),0);
338: else {
339: ind = searchpvar($1);
340: if ( ind == -1 ) {
341: fprintf(stderr,"%s : no such variable.\n",$1);
342: YYABORT;
343: } else
344: $$ = mkfnode(2,I_PVAR,ind,0);
345: }
346: }
347: | pexpr '[' expr ']'
348: {
349: if ( $1->id == I_PVAR || $1->id == I_INDEX ) {
350: appendtonode((NODE)$1->arg[1],(pointer)$3,&a);
351: $1->arg[1] = (pointer)a; $$ = $1;
352: } else {
353: MKNODE(a,$3,0);
354: $$ = mkfnode(2,I_INDEX,(pointer)$1,a);
355: }
356: }
357: | pexpr POINT rawstr
1.4 ! noro 358: { $$ = mkfnode(2,I_POINT,$1,$3); }
1.1 noro 359: ;
360: expr : pexpr
361: { $$ = $1; }
362: | '(' STRUCT rawstr ')' pexpr
363: { $$ = mkfnode(3,I_CAST,structtoindex($3),$5,0); }
364: | expr '=' expr
365: { $$ = mkfnode(2,I_ASSPVAR,$1,$3); }
366: | expr BOPASS expr
367: { $$ = mkfnode(2,I_ASSPVAR,$1,mkfnode(3,I_BOP,$2,$1,$3)); }
368: | expr SELF
369: { $$ = mkfnode(2,I_POSTSELF,$2,$1); }
370: | SELF expr
371: { $$ = mkfnode(2,I_PRESELF,$1,$2); }
372: | '[' node ']'
373: { $$ = mkfnode(1,I_LIST,$2); }
374: | '+' expr %prec PLUS
375: { $$ = $2; }
376: | '-' expr %prec MINUS
377: { $$ = mkfnode(3,I_BOP,$1,0,$2); }
378: | expr '+' expr
379: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
380: | expr '-' expr
381: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
382: | expr '*' expr
383: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
384: | expr '/' expr
385: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
386: | expr '%' expr
387: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
388: | expr '^' expr
389: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
390: | expr CMP expr
391: { $$ = mkfnode(3,I_COP,$2,$1,$3); }
392: | '!' expr
393: { $$ = mkfnode(1,I_NOT,$2); }
394: | expr OR expr
395: { $$ = mkfnode(2,I_OR,$1,$3); }
396: | expr AND expr
397: { $$ = mkfnode(2,I_AND,$1,$3); }
398: | FOP_NOT expr
399: { $$ = mkfnode(3,I_LOP,$1,$2,0); }
400: | expr FOP_AND expr
401: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
402: | expr FOP_OR expr
403: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
404: | expr FOP_IMPL expr
405: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
406: | expr FOP_REPL expr
407: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
408: | expr FOP_EQUIV expr
409: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
410: | expr LOP expr
411: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
412: | expr '?' expr ':' expr
413: { $$ = mkfnode(3,I_CE,$1,$3,$5); }
414: | '<' node '>'
415: { $$ = mkfnode(1,I_EV,$2); }
416: | NEWSTRUCT '(' rawstr ')'
417: { $$ = mkfnode(1,I_NEWCOMP,(int)structtoindex($3)); }
418: ;
419: %%
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>