117b0b798Sbostic/*-
217b0b798Sbostic * Copyright (c) 1980 The Regents of the University of California.
317b0b798Sbostic * All rights reserved.
49e616feaSbostic *
517b0b798Sbostic * %sccs.include.proprietary.c%
6*f7837d38Sbostic *
7*f7837d38Sbostic *	@(#)gram.expr	5.3 (Berkeley) 04/12/91
89e616feaSbostic */
99e616feaSbostic
109e616feaSbostic/*
119e616feaSbostic * gram.expr
129e616feaSbostic *
139e616feaSbostic * Grammar for expressions, f77 compiler pass 1, 4.2 BSD.
149e616feaSbostic *
159e616feaSbostic * University of Utah CS Dept modification history:
169e616feaSbostic *
179e616feaSbostic * $Log:	gram.expr,v $
189e616feaSbosticRevision 1.3  86/02/12  15:28:19  rcs
199e616feaSbostic4.3 F77. C. Keating.
209e616feaSbostic
219e616feaSbostic * Revision 3.2  85/02/15  19:08:53  donn
229e616feaSbostic * Put OPPAREN operators in trees when not optimizing as well as when
239e616feaSbostic * optimizing -- this allows '(1)' to produce a writable temporary instead
249e616feaSbostic * of a read-only constant when passed as an argument to a subroutine.
259e616feaSbostic *
269e616feaSbostic * Revision 3.1  84/10/13  00:42:08  donn
279e616feaSbostic * Installed Jerry Berkman's version with cosmetic changes.
289e616feaSbostic *
299e616feaSbostic * Revision 1.2  84/08/04  21:27:05  donn
309e616feaSbostic * Added Jerry Berkman's fix to stop complaints about parentheses in
319e616feaSbostic * declarations.
329e616feaSbostic *
339e616feaSbostic */
349e616feaSbostic
359e616feaSbosticfunarglist:
369e616feaSbostic		{ $$ = 0; }
379e616feaSbostic	| funargs
389e616feaSbostic	;
399e616feaSbostic
409e616feaSbosticfunargs:  expr
419e616feaSbostic		{ $$ = mkchain($1, CHNULL); }
429e616feaSbostic	| funargs SCOMMA expr
439e616feaSbostic		{ $$ = hookup($1, mkchain($3,CHNULL) ); }
449e616feaSbostic	;
459e616feaSbostic
469e616feaSbostic
479e616feaSbosticexpr:	  uexpr
489e616feaSbostic	| SLPAR expr SRPAR
499e616feaSbostic	{ if (optimflag && parstate != INSIDE && parstate !=INDCL)
509e616feaSbostic			$$ = mkexpr(OPPAREN, $2, ENULL);
519e616feaSbostic		  else $$ = $2;
529e616feaSbostic		}
539e616feaSbostic	| complex_const
549e616feaSbostic	;
559e616feaSbostic
569e616feaSbosticuexpr:	  lhs
579e616feaSbostic	| simple_const
589e616feaSbostic	| expr addop expr   %prec SPLUS
599e616feaSbostic		{ $$ = mkexpr($2, $1, $3); }
609e616feaSbostic	| expr SSTAR expr
619e616feaSbostic		{ $$ = mkexpr(OPSTAR, $1, $3); }
629e616feaSbostic	| expr SSLASH expr
639e616feaSbostic		{ $$ = mkexpr(OPSLASH, $1, $3); }
649e616feaSbostic	| expr SPOWER expr
659e616feaSbostic		{ $$ = mkexpr(OPPOWER, $1, $3); }
669e616feaSbostic	| addop expr  %prec SSTAR
679e616feaSbostic		{ if($1 == OPMINUS)
689e616feaSbostic			$$ = mkexpr(OPNEG, $2, ENULL);
699e616feaSbostic		  else 	$$ = $2;
709e616feaSbostic		}
719e616feaSbostic	| expr relop expr  %prec SEQ
729e616feaSbostic		{ $$ = mkexpr($2, $1, $3); }
739e616feaSbostic	| expr SEQV expr
749e616feaSbostic		{ NO66(".EQV. operator");
759e616feaSbostic		  $$ = mkexpr(OPEQV, $1,$3); }
769e616feaSbostic	| expr SNEQV expr
779e616feaSbostic		{ NO66(".NEQV. operator");
789e616feaSbostic		  $$ = mkexpr(OPNEQV, $1, $3); }
799e616feaSbostic	| expr SOR expr
809e616feaSbostic		{ $$ = mkexpr(OPOR, $1, $3); }
819e616feaSbostic	| expr SAND expr
829e616feaSbostic		{ $$ = mkexpr(OPAND, $1, $3); }
839e616feaSbostic	| SNOT expr
849e616feaSbostic		{ $$ = mkexpr(OPNOT, $2, ENULL); }
859e616feaSbostic	| expr SCONCAT expr
869e616feaSbostic		{ NO66("concatenation operator //");
879e616feaSbostic		  $$ = mkexpr(OPCONCAT, $1, $3); }
889e616feaSbostic	;
899e616feaSbostic
909e616feaSbosticaddop:	  SPLUS		{ $$ = OPPLUS; }
919e616feaSbostic	| SMINUS	{ $$ = OPMINUS; }
929e616feaSbostic	;
939e616feaSbostic
949e616feaSbosticrelop:	  SEQ	{ $$ = OPEQ; }
959e616feaSbostic	| SGT	{ $$ = OPGT; }
969e616feaSbostic	| SLT	{ $$ = OPLT; }
979e616feaSbostic	| SGE	{ $$ = OPGE; }
989e616feaSbostic	| SLE	{ $$ = OPLE; }
999e616feaSbostic	| SNE	{ $$ = OPNE; }
1009e616feaSbostic	;
1019e616feaSbostic
1029e616feaSbosticlhs:	 name
1039e616feaSbostic		{ $$ = mkprim($1, PNULL, CHNULL); }
1049e616feaSbostic	| name substring
1059e616feaSbostic		{ NO66("substring operator :");
1069e616feaSbostic		  if( $1->vclass != CLPARAM ) {
1079e616feaSbostic		  	$$ = mkprim($1, PNULL, $2);
1089e616feaSbostic		  } else {
1099e616feaSbostic			errstr("substring of parameter %s",
1109e616feaSbostic				varstr(VL,$1->varname) );
1119e616feaSbostic			YYERROR ;
1129e616feaSbostic		  }
1139e616feaSbostic		}
1149e616feaSbostic	| name SLPAR funarglist SRPAR
1159e616feaSbostic		{ if( $1->vclass != CLPARAM ) {
1169e616feaSbostic		  	$$ = mkprim($1, mklist($3), CHNULL);
1179e616feaSbostic		  } else {
1189e616feaSbostic			errstr("can not subscript parameter %s",
1199e616feaSbostic				varstr(VL,$1->varname) );
1209e616feaSbostic			YYERROR ;
1219e616feaSbostic		  }
1229e616feaSbostic		}
1239e616feaSbostic	| name SLPAR funarglist SRPAR substring
1249e616feaSbostic		{ if( $1->vclass != CLPARAM ) {
1259e616feaSbostic		  	NO66("substring operator :");
1269e616feaSbostic		  	$$ = mkprim($1, mklist($3), $5);
1279e616feaSbostic		  } else {
1289e616feaSbostic			errstr("can not subscript parameter %s",
1299e616feaSbostic				varstr(VL,$1->varname) );
1309e616feaSbostic			YYERROR ;
1319e616feaSbostic		  }
1329e616feaSbostic		}
1339e616feaSbostic	;
1349e616feaSbostic
1359e616feaSbosticsubstring:  SLPAR opt_expr SCOLON opt_expr SRPAR
1369e616feaSbostic		{ $$ = mkchain($2, mkchain($4,CHNULL)); }
1379e616feaSbostic	;
1389e616feaSbostic
1399e616feaSbosticopt_expr:
1409e616feaSbostic		{ $$ = 0; }
1419e616feaSbostic	| expr
1429e616feaSbostic	;
1439e616feaSbostic
1449e616feaSbostic
1459e616feaSbosticsimple_const:   STRUE	{ $$ = mklogcon(1); }
1469e616feaSbostic	| SFALSE	{ $$ = mklogcon(0); }
1479e616feaSbostic	| SHOLLERITH  { $$ = mkstrcon(toklen, token); }
1489e616feaSbostic	| SICON	= { $$ = mkintcon( convci(toklen, token) ); }
1499e616feaSbostic	| SRCON	= { $$ = mkrealcon(TYREAL, convcd(toklen, token)); }
1509e616feaSbostic	| SDCON	= { $$ = mkrealcon(TYDREAL, convcd(toklen, token)); }
1519e616feaSbostic	;
1529e616feaSbostic
1539e616feaSbosticcomplex_const:  SLPAR uexpr SCOMMA uexpr SRPAR
1549e616feaSbostic		{ $$ = mkcxcon($2,$4); }
1559e616feaSbostic	;
1569e616feaSbostic
1579e616feaSbostic
1589e616feaSbosticfexpr:	  unpar_fexpr
1599e616feaSbostic	| SLPAR fexpr SRPAR
1609e616feaSbostic		{ if (optimflag && parstate != INDCL)
1619e616feaSbostic			$$ = mkexpr(OPPAREN, $2, ENULL);
1629e616feaSbostic		  else $$ = $2;
1639e616feaSbostic		}
1649e616feaSbostic	;
1659e616feaSbostic
1669e616feaSbosticunpar_fexpr:	  lhs
1679e616feaSbostic	| simple_const
1689e616feaSbostic	| fexpr addop fexpr   %prec SPLUS
1699e616feaSbostic		{ $$ = mkexpr($2, $1, $3); }
1709e616feaSbostic	| fexpr SSTAR fexpr
1719e616feaSbostic		{ $$ = mkexpr(OPSTAR, $1, $3); }
1729e616feaSbostic	| fexpr SSLASH fexpr
1739e616feaSbostic		{ $$ = mkexpr(OPSLASH, $1, $3); }
1749e616feaSbostic	| fexpr SPOWER fexpr
1759e616feaSbostic		{ $$ = mkexpr(OPPOWER, $1, $3); }
1769e616feaSbostic	| addop fexpr  %prec SSTAR
1779e616feaSbostic		{ if($1 == OPMINUS)
1789e616feaSbostic			$$ = mkexpr(OPNEG, $2, ENULL);
1799e616feaSbostic		  else	$$ = $2;
1809e616feaSbostic		}
1819e616feaSbostic	| fexpr SCONCAT fexpr
1829e616feaSbostic		{ NO66("concatenation operator //");
1839e616feaSbostic		  $$ = mkexpr(OPCONCAT, $1, $3); }
1849e616feaSbostic	;
185