1/*- 2 * Copyright (c) 1980 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 * 7 * @(#)gram.expr 5.3 (Berkeley) 04/12/91 8 */ 9 10/* 11 * gram.expr 12 * 13 * Grammar for expressions, f77 compiler pass 1, 4.2 BSD. 14 * 15 * University of Utah CS Dept modification history: 16 * 17 * $Log: gram.expr,v $ 18Revision 1.3 86/02/12 15:28:19 rcs 194.3 F77. C. Keating. 20 21 * Revision 3.2 85/02/15 19:08:53 donn 22 * Put OPPAREN operators in trees when not optimizing as well as when 23 * optimizing -- this allows '(1)' to produce a writable temporary instead 24 * of a read-only constant when passed as an argument to a subroutine. 25 * 26 * Revision 3.1 84/10/13 00:42:08 donn 27 * Installed Jerry Berkman's version with cosmetic changes. 28 * 29 * Revision 1.2 84/08/04 21:27:05 donn 30 * Added Jerry Berkman's fix to stop complaints about parentheses in 31 * declarations. 32 * 33 */ 34 35funarglist: 36 { $$ = 0; } 37 | funargs 38 ; 39 40funargs: expr 41 { $$ = mkchain($1, CHNULL); } 42 | funargs SCOMMA expr 43 { $$ = hookup($1, mkchain($3,CHNULL) ); } 44 ; 45 46 47expr: uexpr 48 | SLPAR expr SRPAR 49 { if (optimflag && parstate != INSIDE && parstate !=INDCL) 50 $$ = mkexpr(OPPAREN, $2, ENULL); 51 else $$ = $2; 52 } 53 | complex_const 54 ; 55 56uexpr: lhs 57 | simple_const 58 | expr addop expr %prec SPLUS 59 { $$ = mkexpr($2, $1, $3); } 60 | expr SSTAR expr 61 { $$ = mkexpr(OPSTAR, $1, $3); } 62 | expr SSLASH expr 63 { $$ = mkexpr(OPSLASH, $1, $3); } 64 | expr SPOWER expr 65 { $$ = mkexpr(OPPOWER, $1, $3); } 66 | addop expr %prec SSTAR 67 { if($1 == OPMINUS) 68 $$ = mkexpr(OPNEG, $2, ENULL); 69 else $$ = $2; 70 } 71 | expr relop expr %prec SEQ 72 { $$ = mkexpr($2, $1, $3); } 73 | expr SEQV expr 74 { NO66(".EQV. operator"); 75 $$ = mkexpr(OPEQV, $1,$3); } 76 | expr SNEQV expr 77 { NO66(".NEQV. operator"); 78 $$ = mkexpr(OPNEQV, $1, $3); } 79 | expr SOR expr 80 { $$ = mkexpr(OPOR, $1, $3); } 81 | expr SAND expr 82 { $$ = mkexpr(OPAND, $1, $3); } 83 | SNOT expr 84 { $$ = mkexpr(OPNOT, $2, ENULL); } 85 | expr SCONCAT expr 86 { NO66("concatenation operator //"); 87 $$ = mkexpr(OPCONCAT, $1, $3); } 88 ; 89 90addop: SPLUS { $$ = OPPLUS; } 91 | SMINUS { $$ = OPMINUS; } 92 ; 93 94relop: SEQ { $$ = OPEQ; } 95 | SGT { $$ = OPGT; } 96 | SLT { $$ = OPLT; } 97 | SGE { $$ = OPGE; } 98 | SLE { $$ = OPLE; } 99 | SNE { $$ = OPNE; } 100 ; 101 102lhs: name 103 { $$ = mkprim($1, PNULL, CHNULL); } 104 | name substring 105 { NO66("substring operator :"); 106 if( $1->vclass != CLPARAM ) { 107 $$ = mkprim($1, PNULL, $2); 108 } else { 109 errstr("substring of parameter %s", 110 varstr(VL,$1->varname) ); 111 YYERROR ; 112 } 113 } 114 | name SLPAR funarglist SRPAR 115 { if( $1->vclass != CLPARAM ) { 116 $$ = mkprim($1, mklist($3), CHNULL); 117 } else { 118 errstr("can not subscript parameter %s", 119 varstr(VL,$1->varname) ); 120 YYERROR ; 121 } 122 } 123 | name SLPAR funarglist SRPAR substring 124 { if( $1->vclass != CLPARAM ) { 125 NO66("substring operator :"); 126 $$ = mkprim($1, mklist($3), $5); 127 } else { 128 errstr("can not subscript parameter %s", 129 varstr(VL,$1->varname) ); 130 YYERROR ; 131 } 132 } 133 ; 134 135substring: SLPAR opt_expr SCOLON opt_expr SRPAR 136 { $$ = mkchain($2, mkchain($4,CHNULL)); } 137 ; 138 139opt_expr: 140 { $$ = 0; } 141 | expr 142 ; 143 144 145simple_const: STRUE { $$ = mklogcon(1); } 146 | SFALSE { $$ = mklogcon(0); } 147 | SHOLLERITH { $$ = mkstrcon(toklen, token); } 148 | SICON = { $$ = mkintcon( convci(toklen, token) ); } 149 | SRCON = { $$ = mkrealcon(TYREAL, convcd(toklen, token)); } 150 | SDCON = { $$ = mkrealcon(TYDREAL, convcd(toklen, token)); } 151 ; 152 153complex_const: SLPAR uexpr SCOMMA uexpr SRPAR 154 { $$ = mkcxcon($2,$4); } 155 ; 156 157 158fexpr: unpar_fexpr 159 | SLPAR fexpr SRPAR 160 { if (optimflag && parstate != INDCL) 161 $$ = mkexpr(OPPAREN, $2, ENULL); 162 else $$ = $2; 163 } 164 ; 165 166unpar_fexpr: lhs 167 | simple_const 168 | fexpr addop fexpr %prec SPLUS 169 { $$ = mkexpr($2, $1, $3); } 170 | fexpr SSTAR fexpr 171 { $$ = mkexpr(OPSTAR, $1, $3); } 172 | fexpr SSLASH fexpr 173 { $$ = mkexpr(OPSLASH, $1, $3); } 174 | fexpr SPOWER fexpr 175 { $$ = mkexpr(OPPOWER, $1, $3); } 176 | addop fexpr %prec SSTAR 177 { if($1 == OPMINUS) 178 $$ = mkexpr(OPNEG, $2, ENULL); 179 else $$ = $2; 180 } 181 | fexpr SCONCAT fexpr 182 { NO66("concatenation operator //"); 183 $$ = mkexpr(OPCONCAT, $1, $3); } 184 ; 185