📄 gram.in
字号:
| expr addop expr %prec SPLUS { $$ = mkexpr($2, $1, $3); } | expr SSTAR expr { $$ = mkexpr(OPSTAR, $1, $3); } | expr SSLASH expr { $$ = mkexpr(OPSLASH, $1, $3); } | expr SPOWER expr { $$ = mkexpr(OPPOWER, $1, $3); } | addop expr %prec SSTAR { if($1 == OPMINUS) $$ = mkexpr(OPNEG, $2, ENULL); else $$ = $2; } | expr relop expr %prec SEQ { $$ = mkexpr($2, $1, $3); } | expr SEQV expr { NO66(".EQV. operator"); $$ = mkexpr(OPEQV, $1,$3); } | expr SNEQV expr { NO66(".NEQV. operator"); $$ = mkexpr(OPNEQV, $1, $3); } | expr SOR expr { $$ = mkexpr(OPOR, $1, $3); } | expr SAND expr { $$ = mkexpr(OPAND, $1, $3); } | SNOT expr { $$ = mkexpr(OPNOT, $2, ENULL); } | expr SCONCAT expr { NO66("concatenation operator //"); $$ = mkexpr(OPCONCAT, $1, $3); } ;addop: SPLUS { $$ = OPPLUS; } | SMINUS { $$ = OPMINUS; } ;relop: SEQ { $$ = OPEQ; } | SGT { $$ = OPGT; } | SLT { $$ = OPLT; } | SGE { $$ = OPGE; } | SLE { $$ = OPLE; } | SNE { $$ = OPNE; } ;lhs: name { $$ = mkprim($1, PNULL, CHNULL); } | name substring { NO66("substring operator :"); if( $1->vclass != CLPARAM ) { $$ = mkprim($1, PNULL, $2); } else { errstr("substring of parameter %s", varstr(VL,$1->varname) ); YYERROR ; } } | name SLPAR funarglist SRPAR { if( $1->vclass != CLPARAM ) { $$ = mkprim($1, mklist($3), CHNULL); } else { errstr("can not subscript parameter %s", varstr(VL,$1->varname) ); YYERROR ; } } | name SLPAR funarglist SRPAR substring { if( $1->vclass != CLPARAM ) { NO66("substring operator :"); $$ = mkprim($1, mklist($3), $5); } else { errstr("can not subscript parameter %s", varstr(VL,$1->varname) ); YYERROR ; } } ;substring: SLPAR opt_expr SCOLON opt_expr SRPAR { $$ = mkchain($2, mkchain($4,CHNULL)); } ;opt_expr: { $$ = 0; } | expr ;simple_const: STRUE { $$ = mklogcon(1); } | SFALSE { $$ = mklogcon(0); } | SHOLLERITH { $$ = mkstrcon(toklen, token); } | SICON = { $$ = mkintcon( convci(toklen, token) ); } | SRCON = { $$ = mkrealcon(TYREAL, convcd(toklen, token)); } | SDCON = { $$ = mkrealcon(TYDREAL, convcd(toklen, token)); } ;complex_const: SLPAR uexpr SCOMMA uexpr SRPAR { $$ = mkcxcon($2,$4); } ;fexpr: unpar_fexpr | SLPAR fexpr SRPAR { if (optimflag && parstate != INDCL) $$ = mkexpr(OPPAREN, $2, ENULL); else $$ = $2; } ;unpar_fexpr: lhs | simple_const | fexpr addop fexpr %prec SPLUS { $$ = mkexpr($2, $1, $3); } | fexpr SSTAR fexpr { $$ = mkexpr(OPSTAR, $1, $3); } | fexpr SSLASH fexpr { $$ = mkexpr(OPSLASH, $1, $3); } | fexpr SPOWER fexpr { $$ = mkexpr(OPPOWER, $1, $3); } | addop fexpr %prec SSTAR { if($1 == OPMINUS) $$ = mkexpr(OPNEG, $2, ENULL); else $$ = $2; } | fexpr SCONCAT fexpr { NO66("concatenation operator //"); $$ = mkexpr(OPCONCAT, $1, $3); } ; /* "@(#)gram.exec 4.1 (ULTRIX) 7/17/90" */ /************************************************************************ * * * Copyright (c) 1984 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* @(#)gram.exec 4.3 (Berkeley) 8/7/84 *//* * gram.exec * * Grammar for executable statements, f77 compiler pass 1, 4.2 BSD. * * University of Utah CS Dept modification history: * * $Log: gram.exec,v $ * Revision 3.1 84/10/13 00:36:41 donn * Installed Jerry Berkman's version; preserved comment header. * * Revision 1.3 84/08/06 18:38:43 donn * Fixed a bug in Jerry Berkman's label fixes which caused the same label to * be generated twice for some types of logical IF statements. * * Revision 1.2 84/08/04 21:09:57 donn * Added fixes from Jerry Berkman to allow proper ASSIGNS from format * statement numbers. * */exec: iffable | SDO end_spec intonlyon label intonlyoff opt_comma dospec { if( !do_name_err ) { if($4->labdefined) execerr("no backward DO loops", CNULL); $4->blklevel = blklevel+1; exdo($4->labelno, $7); } } | logif iffable { exendif(); thiswasbranch = NO; } | logif STHEN | SELSEIF end_spec SLPAR expr SRPAR STHEN { exelif($4); lastwasbranch = NO; } | SELSE end_spec { exelse(); lastwasbranch = NO; } | SENDIF end_spec { exendif(); lastwasbranch = NO; } ;logif: SLOGIF end_spec SLPAR expr SRPAR { exif($4); } ;dospec: name SEQUALS exprlist { if( $1->vclass != CLPARAM ) { $$ = mkchain($1, $3); do_name_err = 0; } else { err("symbolic constant not allowed as DO variable"); do_name_err = 1; } } ;iffable: let lhs SEQUALS expr { exequals($2, $4); } | SASSIGN end_spec assignlabel STO name { if( $5->vclass != CLPARAM ) { exassign($5, $3); } else { err("can only assign to a variable"); } } | SCONTINUE end_spec | goto | io { inioctl = NO; } | SARITHIF end_spec SLPAR expr SRPAR label SCOMMA label SCOMMA label { exarif($4, $6, $8, $10); thiswasbranch = YES; } | call { excall($1, PNULL, 0, labarray); } | call SLPAR SRPAR { excall($1, PNULL, 0, labarray); } | call SLPAR callarglist SRPAR { if(nstars < MAXLABLIST) excall($1, mklist($3), nstars, labarray); else err("too many alternate returns"); } | SRETURN end_spec opt_expr { exreturn($3); thiswasbranch = YES; } | stop end_spec opt_expr { exstop($1, $3); thiswasbranch = $1; } ;assignlabel: SICON { $$ = mklabel( convci(toklen, token) ); } ;let: SLET { if(parstate == OUTSIDE) { newproc(); startproc(PNULL, CLMAIN); } if( yystno != 0 && thislabel->labtype != LABFORMAT) if (optimflag) optbuff (SKLABEL, 0, thislabel->labelno, 1); else putlabel(thislabel->labelno); } ;goto: SGOTO end_spec label { exgoto($3); thiswasbranch = YES; } | SASGOTO end_spec name { if( $3->vclass != CLPARAM ) { exasgoto($3); thiswasbranch = YES; } else { err("must go to label or assigned variable"); } } | SASGOTO end_spec name opt_comma SLPAR labellist SRPAR { if( $3->vclass != CLPARAM ) { exasgoto($3); thiswasbranch = YES; } else { err("must go to label or assigned variable"); } } | SCOMPGOTO end_spec SLPAR labellist SRPAR opt_comma expr { if(nstars < MAXLABLIST) if (optimflag) optbuff (SKCMGOTO, fixtype($7), nstars, labarray); else putcmgo (fixtype($7), nstars, labarray); else err("computed GOTO list too long"); } ;opt_comma: | SCOMMA ;call: SCALL end_spec name { nstars = 0; $$ = $3; } ;callarglist: callarg { $$ = ($1 ? mkchain($1,CHNULL) : CHNULL); } | callarglist SCOMMA callarg { if($3) if($1) $$ = hookup($1, mkchain($3,CHNULL)); else $$ = mkchain($3,CHNULL); else $$ = $1; } ;callarg: expr | SSTAR label { if(nstars<MAXLABLIST) labarray[nstars++] = $2; $$ = 0; } ;stop: SPAUSE { $$ = 0; } | SSTOP { $$ = 1; } ;exprlist: expr { $$ = mkchain($1, CHNULL); } | exprlist SCOMMA expr { $$ = hookup($1, mkchain($3,CHNULL) ); } ;end_spec: { if(parstate == OUTSIDE) { newproc(); startproc(PNULL, CLMAIN); } if(parstate < INDATA) enddcl(); if( yystno != 0 && thislabel->labtype != LABFORMAT) if (optimflag) optbuff (SKLABEL, 0, thislabel->labelno, 1); else putlabel(thislabel->labelno); yystno = 0; } ;intonlyon: { intonly = YES; } ;intonlyoff: { intonly = NO; } ; /* Input/Output Statements */io: io1 { endio(); } ;io1: iofmove ioctl | iofmove unpar_fexpr { ioclause(IOSUNIT, $2); endioctl(); } | iofmove SSTAR { ioclause(IOSUNIT, PNULL); endioctl(); } | iofmove SPOWER { ioclause(IOSUNIT, IOSTDERR); endioctl(); } | iofctl ioctl | read ioctl { doio(PNULL); } | read infmt { doio(PNULL); } | read ioctl inlist { doio($3); } | read infmt SCOMMA inlist { doio($4); } | read ioctl SCOMMA inlist { doio($4); } | write ioctl { doio(PNULL); } | write ioctl outlist { doio($3); } | print { doio(PNULL); } | print SCOMMA outlist { doio($3); } ;iofmove: fmkwd end_spec in_ioctl ;fmkwd: SBACKSPACE { iostmt = IOBACKSPACE; } | SREWIND { iostmt = IOREWIND; } | SENDFILE { iostmt = IOENDFILE; } ;iofctl: ctlkwd end_spec in_ioctl ;ctlkwd: SINQUIRE { iostmt = IOINQUIRE; } | SOPEN { iostmt = IOOPEN; } | SCLOSE { iostmt = IOCLOSE; } ;infmt: unpar_fexpr { ioclause(IOSUNIT, PNULL); ioclause(IOSFMT, $1); endioctl(); } | SSTAR { ioclause(IOSUNIT, PNULL); ioclause(IOSFMT, PNULL); endioctl(); } ;ioctl: SLPAR fexpr SRPAR { if($2->headblock.vtype == TYCHAR) { ioclause(IOSUNIT, PNULL); ioclause(IOSFMT, $2); } else ioclause(IOSUNIT, $2); endioctl(); } | SLPAR ctllist SRPAR { endioctl(); } ;ctllist: ioclause | ctllist SCOMMA ioclause ;ioclause: fexpr { ioclause(IOSPOSITIONAL, $1); } | SSTAR { ioclause(IOSPOSITIONAL, PNULL); } | SPOWER { ioclause(IOSPOSITIONAL, IOSTDERR); } | nameeq expr { ioclause($1, $2); } | nameeq SSTAR { ioclause($1, PNULL); } | nameeq SPOWER { ioclause($1, IOSTDERR); } ;nameeq: SNAMEEQ { $$ = iocname(); } ;read: SREAD end_spec in_ioctl { iostmt = IOREAD; } ;write: SWRITE end_spec in_ioctl { iostmt = IOWRITE; } ;print: SPRINT end_spec fexpr in_ioctl { iostmt = IOWRITE; ioclause(IOSUNIT, PNULL); ioclause(IOSFMT, $3); endioctl(); } | SPRINT end_spec SSTAR in_ioctl { iostmt = IOWRITE; ioclause(IOSUNIT, PNULL); ioclause(IOSFMT, PNULL); endioctl(); } ;inlist: inelt { $$ = mkchain($1, CHNULL); } | inlist SCOMMA inelt { $$ = hookup($1, mkchain($3, CHNULL)); } ;inelt: lhs { $$ = (tagptr) $1; } | SLPAR inlist SCOMMA dospec SRPAR { $$ = (tagptr) mkiodo($4,$2); } ;outlist: uexpr { $$ = mkchain($1, CHNULL); } | other { $$ = mkchain($1, CHNULL); } | out2 ;out2: uexpr SCOMMA uexpr { $$ = mkchain($1, mkchain($3, CHNULL) ); } | uexpr SCOMMA other { $$ = mkchain($1, mkchain($3, CHNULL) ); } | other SCOMMA uexpr { $$ = mkchain($1, mkchain($3, CHNULL) ); } | other SCOMMA other { $$ = mkchain($1, mkchain($3, CHNULL) ); } | out2 SCOMMA uexpr { $$ = hookup($1, mkchain($3, CHNULL) ); } | out2 SCOMMA other { $$ = hookup($1, mkchain($3, CHNULL) ); } ;other: complex_const { $$ = (tagptr) $1; } | SLPAR uexpr SCOMMA dospec SRPAR { $$ = (tagptr) mkiodo($4, mkchain($2, CHNULL) ); } | SLPAR other SCOMMA dospec SRPAR { $$ = (tagptr) mkiodo($4, mkchain($2, CHNULL) ); } | SLPAR out2 SCOMMA dospec SRPAR { $$ = (tagptr) mkiodo($4, $2); } ;in_ioctl: { startioctl(); } ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -