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