Annotation of OpenXM_contrib2/asir2000/parse/parse.y, Revision 1.1
1.1 ! noro 1: /* $OpenXM: OpenXM/src/asir99/parse/parse.y,v 1.2 1999/11/18 05:42:03 noro Exp $ */
! 2: %{
! 3: #define malloc(x) GC_malloc(x)
! 4: #define realloc(x,y) GC_realloc(x,y)
! 5: #define free(x) GC_free(x)
! 6:
! 7: #if defined(THINK_C)
! 8: #define alloca(x) GC_malloc(x)
! 9: #endif
! 10: #if defined(TOWNS)
! 11: #include <alloca.h>
! 12: #endif
! 13: #include <ctype.h>
! 14: #include "ca.h"
! 15: #if !defined(THINK_C)
! 16: #include <sys/types.h>
! 17: #include <sys/stat.h>
! 18: #endif
! 19: #include "parse.h"
! 20:
! 21: #define NOPR (prresult=0)
! 22:
! 23: extern int gdef;
! 24: extern SNODE parse_snode;
! 25: extern int main_parser;
! 26:
! 27: int prresult;
! 28:
! 29: static int ind;
! 30: static FNODE t;
! 31: static NODE a,b;
! 32: static NODE2 a2;
! 33: static pointer val;
! 34: extern jmp_buf env;
! 35: %}
! 36:
! 37: %start start
! 38:
! 39: %union {
! 40: FNODE f;
! 41: SNODE s;
! 42: NODE n;
! 43: NODE2 n2;
! 44: int i;
! 45: pointer p;
! 46: }
! 47:
! 48: %token <i> STRUCT POINT NEWSTRUCT ANS FDEF PFDEF GLOBAL CMP OR AND CAR CDR
! 49: %token <i> DO WHILE FOR IF ELSE BREAK RETURN CONTINUE PARIF MAP TIMER GF2NGEN GFPNGEN GETOPT
! 50: %token <i> FOP_AND FOP_OR FOP_IMPL FOP_REPL FOP_EQUIV FOP_NOT LOP
! 51: %token <p> FORMULA UCASE LCASE STR SELF BOPASS
! 52: %token <p> '+' '-' '*' '/' '^' '%'
! 53:
! 54: %type <p> desc rawstr
! 55: %type <f> expr pexpr opt
! 56: %type <s> stat complex
! 57: %type <n> stats node _node pvars fields members optlist
! 58:
! 59: %right '=' BOPASS
! 60: %right '?' ':'
! 61: %right FOP_NOT
! 62: %left FOP_EQUIV
! 63: %left FOP_REPL
! 64: %left FOP_IMPL
! 65: %left FOP_OR
! 66: %left FOP_AND
! 67: %left LOP
! 68: %left LCASE
! 69: %left OR
! 70: %left AND
! 71: %left '&'
! 72: %left CMP
! 73: %left '+' '-'
! 74: %left PLUS
! 75: %left MINUS
! 76: %left '*' '/' '%'
! 77: %right '^'
! 78: %right '!'
! 79: %right SELF
! 80: %left POINT
! 81:
! 82: %%
! 83:
! 84: start : stat
! 85: { parse_snode = $1; YYACCEPT; }
! 86: ;
! 87: stat : tail
! 88: { $$ = 0; }
! 89: | GLOBAL { gdef=1; } pvars { gdef=0; } tail
! 90: { $$ = 0; }
! 91: | STRUCT rawstr '{' fields '}' tail
! 92: { structdef($2,$4); $$ = 0; }
! 93: | STRUCT rawstr '{' fields '}' pvars tail
! 94: { structdef($2,$4); setstruct($2,$6); $$ = 0; }
! 95: | STRUCT rawstr pvars tail
! 96: { setstruct($2,$3); $$ = 0; }
! 97: | expr tail
! 98: { $$ = mksnode(1,S_SINGLE,$1); }
! 99: | complex
! 100: { $$ = $1; }
! 101: | BREAK tail
! 102: { $$ = mksnode(0,S_BREAK); }
! 103: | CONTINUE tail
! 104: { $$ = mksnode(0,S_CONTINUE); }
! 105: | RETURN tail
! 106: { $$ = mksnode(1,S_RETURN,0); }
! 107: | RETURN expr tail
! 108: { $$ = mksnode(1,S_RETURN,$2); }
! 109: | IF '(' node ')' stat
! 110: { $$ = mksnode(4,S_IFELSE,$1,$3,$5,0); $5?$$->ln=$5->ln:0; NOPR; }
! 111: | IF '(' node ')' stat ELSE stat
! 112: { $$ = mksnode(4,S_IFELSE,$1,$3,$5,$7); $7?$$->ln=$7->ln:0; NOPR; }
! 113: | FOR '(' node ';' node ';' node ')' stat
! 114: { $$ = mksnode(5,S_FOR,$1,$3,$5?$5:ONENODE,$7,$9); $9?$$->ln=$9->ln:0; NOPR; }
! 115: | WHILE '(' node ')' stat
! 116: { $$ = mksnode(5,S_FOR,$1,0,$3,0,$5); $5?$$->ln=$5->ln:0; NOPR; }
! 117: | DO stat WHILE '(' node ')' tail
! 118: { $$ = mksnode(3,S_DO,$1,$2,$5); }
! 119: | LCASE '(' node ')' ':' '=' expr tail
! 120: { $$ = mksnode(3,S_PFDEF,$1,$3,$7); NOPR; }
! 121: | PFDEF LCASE '(' node ')'
! 122: { $$ = mksnode(3,S_PFDEF,$2,$4,0); NOPR; }
! 123: | FDEF LCASE { mkpvs(); } '(' node ')' desc '{' stats '}'
! 124: {
! 125: mkuf($2,asir_infile->name,$5,
! 126: mksnode(1,S_CPLX,$9),$1,asir_infile->ln,$7);
! 127: $$ = 0; NOPR;
! 128: }
! 129: | error tail
! 130: { yyerrok; $$ = 0; }
! 131: ;
! 132: tail : ';'
! 133: { if ( main_parser ) prresult = 1; }
! 134: | '$'
! 135: { if ( main_parser ) prresult = 0; }
! 136: desc :
! 137: { $$ = 0; }
! 138: | STR
! 139: { $$ = $1; }
! 140: ;
! 141: complex : '{' stats '}'
! 142: { $$ = mksnode(1,S_CPLX,$2); }
! 143: ;
! 144: fields :
! 145: { $$ = 0; }
! 146: | fields members tail
! 147: { MKNODE(a,0,$2); appendtonode($1,(pointer)a,&$$); }
! 148: | fields STRUCT rawstr members tail
! 149: { MKNODE(a,$3,$4); appendtonode($1,(pointer)a,&$$); }
! 150: ;
! 151: members : rawstr
! 152: { MKNODE($$,$1,0); }
! 153: | members ',' rawstr
! 154: { appendtonode($1,$3,&$$); }
! 155: ;
! 156: pvars : UCASE
! 157: { val = (pointer)makepvar($1); MKNODE($$,val,0); }
! 158: | pvars ',' UCASE
! 159: { appendtonode($1,(pointer)makepvar($3),&$$); }
! 160: ;
! 161: stats :
! 162: { $$ = 0; }
! 163: | stats stat
! 164: { appendtonode($1,(pointer)$2,&$$); }
! 165: ;
! 166: node :
! 167: { $$ = 0; }
! 168: | _node
! 169: { $$ = $1; }
! 170: ;
! 171: _node : expr
! 172: { MKNODE($$,$1,0); }
! 173: | _node ',' expr
! 174: { appendtonode($1,(pointer)$3,&$$); }
! 175: ;
! 176: optlist : opt
! 177: { MKNODE($$,$1,0); }
! 178: | optlist ',' opt
! 179: { appendtonode($1,(pointer)$3,&$$); }
! 180: ;
! 181: rawstr : UCASE
! 182: { $$ = $1; }
! 183: | LCASE
! 184: { $$ = $1; }
! 185: ;
! 186: opt : rawstr '=' expr
! 187: { $$ = mkfnode(2,I_OPT,$1,$3); }
! 188: ;
! 189: pexpr : STR
! 190: { $$ = mkfnode(1,I_STR,$1); }
! 191: | FORMULA
! 192: { $$ = mkfnode(1,I_FORMULA,$1); }
! 193: | ANS
! 194: { $$ = mkfnode(1,I_ANS,$1); }
! 195: | GF2NGEN
! 196: { $$ = mkfnode(0,I_GF2NGEN); }
! 197: | GFPNGEN
! 198: { $$ = mkfnode(0,I_GFPNGEN); }
! 199: | LCASE
! 200: {
! 201: FUNC f;
! 202:
! 203: searchf(noargsysf,$1,&f);
! 204: if ( f )
! 205: $$ = mkfnode(2,I_FUNC,f,0);
! 206: else {
! 207: searchc($1,&f);
! 208: if ( f )
! 209: $$ = mkfnode(2,I_FUNC,f,mkfnode(1,I_LIST,0));
! 210: else {
! 211: searchf(sysf,$1,&f);
! 212: if ( !f )
! 213: searchf(ubinf,$1,&f);
! 214: if ( !f )
! 215: searchpf($1,&f);
! 216: if ( !f )
! 217: searchf(usrf,$1,&f);
! 218: if ( f )
! 219: makesrvar(f,(P *)&val);
! 220: else
! 221: makevar($1,(P *)&val);
! 222: $$ = mkfnode(1,I_FORMULA,val);
! 223: }
! 224: }
! 225: }
! 226: | LCASE '(' node ')'
! 227: {
! 228: searchf(sysf,$1,(FUNC *)&val);
! 229: if ( !val )
! 230: searchf(ubinf,$1,(FUNC *)&val);
! 231: if ( !val )
! 232: searchpf($1,(FUNC *)&val);
! 233: if ( !val )
! 234: searchf(usrf,$1,(FUNC *)&val);
! 235: if ( !val )
! 236: appenduf($1,(FUNC *)&val);
! 237: $$ = mkfnode(2,I_FUNC,val,mkfnode(1,I_LIST,$3));
! 238: }
! 239:
! 240: | LCASE '(' node '|' optlist ')'
! 241: {
! 242: searchf(sysf,$1,(FUNC *)&val);
! 243: if ( !val )
! 244: searchf(ubinf,$1,(FUNC *)&val);
! 245: if ( !val )
! 246: searchpf($1,(FUNC *)&val);
! 247: if ( !val )
! 248: searchf(usrf,$1,(FUNC *)&val);
! 249: if ( !val )
! 250: appenduf($1,(FUNC *)&val);
! 251: $$ = mkfnode(3,I_FUNC_OPT,val,
! 252: mkfnode(1,I_LIST,$3),mkfnode(1,I_LIST,$5));
! 253: }
! 254: | LCASE '{' node '}' '(' node ')'
! 255: {
! 256: searchpf($1,(FUNC *)&val);
! 257: $$ = mkfnode(2,I_PFDERIV,val,mkfnode(1,I_LIST,$6),mkfnode(1,I_LIST,$3));
! 258: }
! 259: | GETOPT '(' rawstr ')'
! 260: {
! 261: $$ = mkfnode(2,I_GETOPT,$3);
! 262: }
! 263: | MAP '(' LCASE ',' node ')'
! 264: {
! 265: searchf(sysf,$3,(FUNC *)&val);
! 266: if ( !val )
! 267: searchf(ubinf,$3,(FUNC *)&val);
! 268: if ( !val )
! 269: searchpf($3,(FUNC *)&val);
! 270: if ( !val )
! 271: searchf(usrf,$3,(FUNC *)&val);
! 272: if ( !val )
! 273: appenduf($3,(FUNC *)&val);
! 274: $$ = mkfnode(2,I_MAP,val,mkfnode(1,I_LIST,$5));
! 275: }
! 276: | TIMER '(' expr ',' expr ',' expr ')'
! 277: {
! 278: $$ = mkfnode(3,I_TIMER,$3,$5,$7);
! 279: }
! 280: | PARIF '(' LCASE ',' node ')'
! 281: {
! 282: searchf(parif,$3,(FUNC *)&val);
! 283: if ( !val )
! 284: mkparif($3,(FUNC *)&val);
! 285: $$ = mkfnode(2,I_FUNC,val,mkfnode(1,I_LIST,$5));
! 286: }
! 287: | '(' '*' expr ')' '(' node ')'
! 288: {
! 289: $$ = mkfnode(2,I_IFUNC,$3,mkfnode(1,I_LIST,$6));
! 290: }
! 291: | CAR '(' expr ')'
! 292: { $$ = mkfnode(1,I_CAR,$3); }
! 293: | CDR '(' expr ')'
! 294: { $$ = mkfnode(1,I_CDR,$3); }
! 295: | '(' expr ')'
! 296: { $$ = $2; }
! 297: | UCASE
! 298: {
! 299: if ( main_parser )
! 300: $$ = mkfnode(2,I_PVAR,makepvar($1),0);
! 301: else {
! 302: ind = searchpvar($1);
! 303: if ( ind == -1 ) {
! 304: fprintf(stderr,"%s : no such variable.\n",$1);
! 305: YYABORT;
! 306: } else
! 307: $$ = mkfnode(2,I_PVAR,ind,0);
! 308: }
! 309: }
! 310: | pexpr '[' expr ']'
! 311: {
! 312: if ( $1->id == I_PVAR || $1->id == I_INDEX ) {
! 313: appendtonode((NODE)$1->arg[1],(pointer)$3,&a);
! 314: $1->arg[1] = (pointer)a; $$ = $1;
! 315: } else {
! 316: MKNODE(a,$3,0);
! 317: $$ = mkfnode(2,I_INDEX,(pointer)$1,a);
! 318: }
! 319: }
! 320: | pexpr POINT rawstr
! 321: { memberofstruct($1,$3,&$$); }
! 322: ;
! 323: expr : pexpr
! 324: { $$ = $1; }
! 325: | '(' STRUCT rawstr ')' pexpr
! 326: { $$ = mkfnode(3,I_CAST,structtoindex($3),$5,0); }
! 327: | expr '=' expr
! 328: { $$ = mkfnode(2,I_ASSPVAR,$1,$3); }
! 329: | expr BOPASS expr
! 330: { $$ = mkfnode(2,I_ASSPVAR,$1,mkfnode(3,I_BOP,$2,$1,$3)); }
! 331: | expr SELF
! 332: { $$ = mkfnode(2,I_POSTSELF,$2,$1); }
! 333: | SELF expr
! 334: { $$ = mkfnode(2,I_PRESELF,$1,$2); }
! 335: | '[' node ']'
! 336: { $$ = mkfnode(1,I_LIST,$2); }
! 337: | '+' expr %prec PLUS
! 338: { $$ = $2; }
! 339: | '-' expr %prec MINUS
! 340: { $$ = mkfnode(3,I_BOP,$1,0,$2); }
! 341: | expr '+' expr
! 342: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
! 343: | expr '-' expr
! 344: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
! 345: | expr '*' expr
! 346: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
! 347: | expr '/' expr
! 348: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
! 349: | expr '%' expr
! 350: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
! 351: | expr '^' expr
! 352: { $$ = mkfnode(3,I_BOP,$2,$1,$3); }
! 353: | expr CMP expr
! 354: { $$ = mkfnode(3,I_COP,$2,$1,$3); }
! 355: | '!' expr
! 356: { $$ = mkfnode(1,I_NOT,$2); }
! 357: | expr OR expr
! 358: { $$ = mkfnode(2,I_OR,$1,$3); }
! 359: | expr AND expr
! 360: { $$ = mkfnode(2,I_AND,$1,$3); }
! 361: | FOP_NOT expr
! 362: { $$ = mkfnode(3,I_LOP,$1,$2,0); }
! 363: | expr FOP_AND expr
! 364: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
! 365: | expr FOP_OR expr
! 366: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
! 367: | expr FOP_IMPL expr
! 368: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
! 369: | expr FOP_REPL expr
! 370: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
! 371: | expr FOP_EQUIV expr
! 372: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
! 373: | expr LOP expr
! 374: { $$ = mkfnode(3,I_LOP,$2,$1,$3); }
! 375: | expr '?' expr ':' expr
! 376: { $$ = mkfnode(3,I_CE,$1,$3,$5); }
! 377: | '<' node '>'
! 378: { $$ = mkfnode(1,I_EV,$2); }
! 379: | NEWSTRUCT '(' rawstr ')'
! 380: { $$ = mkfnode(1,I_NEWCOMP,(int)structtoindex($3)); }
! 381: ;
! 382: %%
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>