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