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