aboutsummaryrefslogtreecommitdiff
path: root/unix/boot/spp/rpp/rpprat/forcod.r
blob: 9d389f5e25f616eff5ff91d42667e2ced8a48174 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#-h-  forcod			 2259  local   12/01/80  15:54:07
# forcod - beginning of for statement
   include  defs

   subroutine forcod (lab)
   integer lab

   include COMMON_BLOCKS

   character t, token (MAXTOK)
   character gettok, gnbtok

   integer i, j, nlpar
   integer length, labgen

   string ifnot "if (.not."
   string serrchk ".and.(.not.xerflg))) "

   lab = labgen (3)
   call outcon (0)
   if (gnbtok (token, MAXTOK) != LPAREN) {
      call synerr ("missing left paren.")
      return
      }
   if (gnbtok (token, MAXTOK) != SEMICOL) {   # real init clause
      call pbstr (token)
      call outtab
      call eatup
      call outdwe
      }
   if (gnbtok (token, MAXTOK) == SEMICOL)   # empty condition
      call outcon (lab)
   else {   # non-empty condition
      call pbstr (token)
      call outnum (lab)
      call outtab
      call outstr (ifnot)
      call outch (LPAREN)
      nlpar = 0
      while (nlpar >= 0) {
	 t = gettok (token, MAXTOK)
	 if (t == SEMICOL)
	    break
	 if (t == LPAREN)
	    nlpar = nlpar + 1
	 else if (t == RPAREN)
	    nlpar = nlpar - 1
	 if (t == EOF) {
	    call pbstr (token)
	    return
	    }
	 if (t == ALPHA)
	    call squash (token)
	 if (t != NEWLINE & t != UNDERLINE)
	    call outstr (token)
	 }

      # name encountered for which error checking is required?
      if (ername == YES)
	 call outstr (serrchk)
      else {
	  call outch (RPAREN)
	  call outch (RPAREN)
	  call outch (BLANK)
	  }
      call outgo (lab+2)			# error checking below (errgo)
      if (nlpar < 0)
	 call synerr ("invalid for clause.")
      }
   fordep = fordep + 1	 # stack reinit clause
   j = 1
   for (i = 1; i < fordep; i = i + 1)	# find end
      j = j + length (forstk (j)) + 1
   forstk (j) = EOS   # null, in case no reinit
   nlpar = 0
   t = gnbtok (token, MAXTOK)
   call pbstr (token)
   while (nlpar >= 0) {
      t = gettok (token, MAXTOK)
      if (t == LPAREN)
	 nlpar = nlpar + 1
      else if (t == RPAREN)
	 nlpar = nlpar - 1
      if (t == EOF) {
	 call pbstr (token)
	 break
	 }
      if (nlpar >= 0 & t != NEWLINE & t != UNDERLINE) {
	 if (t == ALPHA)
	    call squash (token)
	 if (j + length (token) >= MAXFORSTK)
	    call baderr ("for clause too long.")
	 call scopy (token, 1, forstk, j)
	 j = j + length (token)
	 }
      }
   lab = lab + 1   # label for next's
   call indent (1)
   call errgo
   return
   end