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