File: fact.f

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (674 lines) | stat: -rw-r--r-- 16,437 bytes parent folder | download
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
      subroutine fact
c     ======================================================================
c     analyseur de facteurs
c     ======================================================================
c     
c     Copyright INRIA
      include '../stack.h'
c     
      parameter (nz1=nsiz-1,nz2=nsiz-2)
      logical eqid,eptover
      integer r,excnt,psym,chars
      integer id(nsiz),op,fun1
      integer star,dstar,semi,eol,blank,percen
      integer comma,lparen,rparen,hat,dot,equal
      integer quote,left,right,colon,slash,not
      integer num,name,cmt
      integer cconc,extrac,rconc
      logical recurs,compil,first,dotsep,nullarg,ok
      integer setgetmode
      
      data star/47/,dstar/62/,semi/43/,eol/99/,blank/40/,percen/56/
      data comma/52/,lparen/41/,rparen/42/, hat/62/,dot/51/,equal/50/
      data quote/53/,left/54/,right/55/,colon/44/,slash/48/,not/61/

      data num/0/,name/1/,cmt/2/
      data cconc/1/,extrac/3/,rconc/4/
c     
c     
      r = rstk(pt)
c     
      if (ddt .eq. 4) then
         write(buf(1:12),'(3i4)') pt,r,sym
         call basout(io,wte,' factor pt:'//buf(1:4)//' rstk(pt):'//
     &        buf(5:8)//' sym:'//buf(9:12))
      endif
c     
      nullarg=.true.
      dotsep=.false.
      ir=r/100
      if(ir.ne.3) goto 01
      goto(25,26,99,29,99,51,43,48,55,62,65,66,41),r-300
      goto 99
c     
 01   if (sym.eq.left) go to 20
      if (sym.eq.quote) go to 15
      if (sym.eq.num) go to 10
      excnt = 0
      if (sym .eq. name) go to 30
      if (sym .eq. colon) then
         call getsym
c     call eye()
         if(comp(1).ne.0) then
            if (compil(21,0,0,0,0)) then 
               if (err.gt.0) return
            endif
         endif
         fun=6
         fin=13
         rhs=0
         goto 53
      endif
      id(1) = blank
      if (sym .eq. lparen) go to 36

      if(err1.gt.0) then
         pt=pt+1
 02      pt=pt-1
         r=rstk(pt)
         if(int(r/100).ne.3) goto 02
         goto(25,26,99,29,99,51,43,48,55,62,65,66),r-300
      endif
      call error(2)
c      if (err .gt. 0) return
      return
c     
c     put something on the stack
      
c     --- single number, getsym stored it in stk(vsiz)
c     
 10   call getnum
      if(err.gt.0) return
      psym=num
      call getsym
      go to 60
c     
c     --- string
c     
 15   call getstr
      if(err.gt.0) return
      call getsym
      go to 60
c     
c     --- matrix defined by bracket operators
c     
 20   continue
      if (eptover(0,psiz-3))  return
      pt=pt+1
      rstk(pt)=0
      pstk(pt)=0
c     
 21   continue
      pt=pt+1
      pstk(pt)=0
      call getsym
c     
 22   if (sym.eq.cmt) call parsecomment
      if (sym.eq.semi .or. sym.eq.eol .or.sym.eq.right) go to 27
      if (sym .eq. num .and.char1.eq.dot.and.
     $     lin(lpt(4)-2).ne.blank) then
c     .  to return an error on [1.000.3,...] 
         lpt(2)=lpt(4)+1
         call error(276)
         return
      endif

      if (sym .eq. comma) then
         call getsym
c        comment next line to disallow Matlab syntax like [1,2,,;3,4]  
         goto 22
      endif
 
      rstk(pt) = 301
c     get next entry or block
      icall=1
c     *call* expr
      return
c     catenate  entry or block with previous on the same row
 25   continue
      if(err1.ne.0) goto 22
      pstk(pt)=pstk(pt)+1
      if(pstk(pt).le.1) goto 22
      pstk(pt)=1
      rstk(pt)= 302
      fin=cconc
      rhs=2
      icall=4
c     *call* allops(cconc)
      return
 26   go to 22
 27   pt=pt-1
      if (sym.eq.semi .and. char1.eq.eol) call getsym
c     catenate row with previous rows
      if(err1.ne.0) goto 29
      if(pstk(pt+1).gt.0) pstk(pt)=pstk(pt)+1
      if(pstk(pt).le.1) goto 29
      pstk(pt)=1
      rstk(pt)= 304
      fin=rconc
      rhs=2
      icall=4
c     *call* allops(rconc)
      return
 29   if (sym .eq. eol) then
         if(comp(1).ne.0) call seteol
         if(lpt(4).eq.lpt(6))  then
            call getlin(0,0) 
         else
            lpt(4)=lpt(4)+1
            call getsym
         endif
      endif
      if (sym.eq.eol.and.err1.ne.0) then
         pt=pt-1 
         go to 60
      endif
      if (sym .ne. right) go to 21
      if (pstk(pt).le.0) then
         call defmat
         if(err.gt.0) return
      endif
      pt=pt-1
      call getsym
      go to 60
c     
c     --- named variable, function evaluation or matrix element   x(...)
c     
 30   call putid(id,syn(1))
 31   call getsym
      
      if (sym .eq. lparen) then
c     .     check for blank separator in matrix definition
         if(abs(lin(lpt(3)-2)).ne.blank.or.rstk(pt-2).ne.301) then
c     .     it is really x(....)
            dotsep=.false.
            goto 36
         endif
      endif
      if (sym.eq.dot.and.(abs(char1) .lt. blank.or.
     $     char1.eq.percen)) then
         dotsep=.true.
         goto 36
      endif
      fin=0
      rhs = 0
c     
c     -- put a named variable in the stack
c     check for indirect loading
      fin=setgetmode(id)
      call stackg(id)
      if (err .gt. 0) return
      if(fin.ne.0.or.err1.ne.0) goto 60
c     
      if(comp(1).eq.0) then
         fun1=fun
         call funs(id)
         if(err.gt.0) return
         if (fun .gt. 0) then
            call varfunptr(id,fun,fin)
            goto 60
         endif
c     this should never happen???
         fun=fun1
         fin=setgetmode(id)
         call stackg(id)
         if (err .gt. 0) return
         if (fin .eq. 0) then
            if(err1.ne.0) goto 60
            call  putid(ids(1,pt+1),id)
            call error(4)
            if (err .gt. 0) return
         endif
         go to 60
      endif
      
c     
 36   continue
c     --- function evaluation or variable element   x(...)
      if ( eptover(1,psiz-1))  return
c     x(...) :store object or function name

      rstk(pt)=0
      pstk(pt)=lhs
      call putid(ids(1,pt),id)
c     %% added for runtime set rhs args by list extraction (ss)
      fun1=fun
      fun=0
      if(id(1).ne.blank) then
         fin=-2
         call funs(id)
         if (fun .ne. 0) then
c     .     name is a function name, check if it is a call or a reference
         else
c     .     allow indirect reference to variables
            fun=-1
         endif
         lhs=1

c       %% next lines added  for runtime set rhs args number
         if(comp(1).ne.0) then
            if (compil(21,0,0,0,0)) then 
               if (err.gt.0) return
            endif
         endif
      endif


c     
c     eval function or variable arguments
 38   call getsym
c     
      if(.not.dotsep.and.sym.eq.rparen) then
c     .  function has no input parameter
         if(rstk(pt).lt.0) then
c     .    a(...)()
            call error(21)
            if (err .gt. 0) return
         endif
         excnt=-1
         goto 45
      endif
c
      if(dotsep) then
         if (sym.ne.name) then
            call error(2)
            if (err .gt. 0) return
         endif
c     .  create a string variable containing name syn
         icount=icount+1
         if(comp(1).ne.0) then
            if(compil(23,syn,0,0,0)) then
               if(err.gt.0) return
            endif
         else
            call name2var(syn)
         endif
         dotsep=.false.
         excnt=excnt+1
         goto 45
      endif

      fun1=fun
      if(sym.eq.name.and.char1.eq.lparen) then
c     . check for a function name
         fun=0
         fin=-2
         call funs(syn)
         if (fun .ne. 0) then
c     .     name is a function name, check if it is a call or a reference

         else
            fun=fun1
         endif
      endif

      excnt = excnt+1
c
      if(sym.ne.comma) goto 40

c     args(, ..) or (.. ,, ..) or (.. ,) syntax
 39   if (nullarg) then 
c     .  default argument allowed
         if(comp(1).eq.0) then
            top=top+1
            call objvide(' ', top)
         else
            if(compil(24,0,0,0,0)) then
               if(err.gt.0) return
            endif
         endif
         if(sym.eq.rparen) then
c     .     (.. ,) syntax
            goto 45
         endif
         goto 44
      else
         lpt(2)=lpt(4)
         call error(46)
         return
      endif

 40   if(sym.ne.name.or.char1.ne.equal) goto 42
c     next lines to manage named arguments (..,a=..)

      fun=fun1
      lpt4=lpt(4)
      call fortrangetch
      if(char1.eq.equal) then
c     check for a==
         lpt(4)=lpt4
         goto 42
      endif
      if(ids(1,pt).eq.blank) then 
c     .  (x=2) syntax for a a factor ->(x==2)
         lpt(4)=lpt4
         char1=equal
         goto 42
      endif
c     it is really a named argument
      if ( eptover(1,psiz-1))  return
      ids(1,pt)=rhs
      ids(2,pt)=lhs
      ids(3,pt)=lct(4)
      ids(4,pt)=fun
      lct(4)=-1
      rstk(pt)=313
      lpt(4)=lpt(2)
      pstk(pt)=excnt
      char1=blank
      icall=7
      return
c     *call* parse
 41   continue
      rhs=ids(1,pt)
      lhs=ids(2,pt)
      lct(4)=ids(3,pt)
      excnt = pstk(pt)
      fun=ids(4,pt)
      pt = pt-1
c     end of special code to manage named argument
      goto 44
c
 42   continue
c     argument is a standard expression
      if ( eptover(1,psiz-1))  return
      pstk(pt) = excnt
      ids(1,pt)=fun
      ids(2,pt)=fun1
      rstk(pt) = 307
      icall=1
c     *call* expr
      return
 43   excnt = pstk(pt)
      fun=ids(2,pt)
      pt = pt-1
c
 44   continue
c     one more argument ?
      if (sym .eq. comma) then
         if (char1.eq.rparen) then
            call getsym
            excnt=excnt+1
            goto 39
         endif
         go to 38
      endif
c     end of argument sequence or recursive extraction ?
      if (sym .ne. rparen) then
         lpt(2)=lpt(3)+1
         call error(3)
         return
      endif
c     
 45   continue
c     end of argument sequence or recursive extraction 
      call getsym
      recurs=.false.
      if( sym .eq. dot.and.(abs(char1) .lt. blank.or.
     $     char1.eq.percen)) then
         dotsep=.true.
c     .  recursive extraction
         if(excnt.gt.1) then
            if(comp(1).eq.0) then
c     .     form  list with individual indexes
               call mkindx(0,excnt)
               if(err.gt.0) return
            else
               if (compil(19,0,excnt,0,0)) then 
                  if (err.gt.0) return
               endif
            endif
            excnt=1
            recurs=.true.
         endif
         if(excnt.ge.0) rstk(pt)=rstk(pt)-1
         excnt=0
c     .  get one more argument of the recursive extraction
         goto 38
      elseif(sym.eq.lparen) then
c        . check for blank separator in matrix definition
         if(abs(lin(lpt(3)-2)).eq.blank.and.rstk(pt-3).eq.301) then
c     .     end of argument sequence
            goto 46
         endif
c     .  recursive extraction
         if(excnt.gt.1) then
            if(comp(1).eq.0) then
c     .     form  list with individual indexes
               call mkindx(0,excnt)
               if(err.gt.0) return
            else
               if (compil(19,0,excnt,0,0)) then 
                  if (err.gt.0) return
               endif
            endif
            excnt=1
            recurs=.true.
         endif
         if(excnt.ge.0) rstk(pt)=rstk(pt)-1
         excnt=0
c     .  get one more argument of the recursive extraction
         goto 38
      elseif(rstk(pt).lt.0) then
c     .  all args of the recursive extraction have been computed
c     .  store them into a list
         if(comp(1).eq.0) then
c     .     form  list with individual indexes
            call mkindx(1-rstk(pt),excnt)
            if(err.gt.0) return
            excnt=1
            recurs=.true.
         else
            if (compil(19,1-rstk(pt),excnt,0,0)) then 
               if (err.gt.0) return
               excnt=1
            endif
         endif
      endif

 46   continue
c     all arguments evaluated
      call putid(id,ids(1,pt))
      lhs=pstk(pt)
      pt=pt-1
      if (id(1) .eq. blank) then
         if(lhs.ne.excnt) then
            call error(41)
            if(err.gt.0) return
         endif
         if (recurs) then
            call error(250)
            return
         endif
         go to 60
      endif
      rhs = excnt

c     get function or variable to be evaluated for computed arguments
      fin=0
c      if(comp(1).eq.0) then
         fin=-2
         call stackg(id)
         if(err.gt.0) return
c      endif
      if(comp(1).ne.0) goto 47

      if(fin.eq.0) then
c     .  id is not a standard variable
         if (recurs) then
            call error(250)
            return
         endif
         if(err1.gt.0) goto 60
         call funs(id)
         if(err.gt.0) return

         if(fun.gt.0)  goto 53
         fin=-2
         call stackg(id)
         if(err.gt.0) return
         if(fin.eq.0) then
            if(err1.gt.0) goto 60
            call error(4)
            if(err.gt.0) return
         endif
      endif
      if(fin.gt.0) goto 50
      if(rhs.eq.0) goto 60

      call isafunptr(top,id,ifun,ifin)
 
      if(ifun.ne.0) then
         top=top-1
         fun=ifun
         fin=ifin
         goto 53
      endif
c     
c     --- variable is a matrix or list :extraction
c     
 47   rhs=rhs+1
      if ( eptover(1,psiz-1)) return
      rstk(pt)=308
      fin=extrac
      icall=4
c     *call* allops(extrac)
      return
 48   pt=pt-1
      goto 60
c     
c     --- variable is macro : execution
c     
 50   if ( eptover(1,psiz-1)) return
      call putid(id,ids(1,pt))
      rstk(pt)=306
      pstk(pt)=wmac
      icall=5
c     *call* macro
      return
 51   wmac=pstk(pt)
      pt=pt-1
      go to 60
c     
c     evaluate matrix function
 53   if ( eptover(1,psiz-1))  return
      rstk(pt) = 309
      icall=9
c     *call* matfns
      return
 55   pt = pt-1
      go to 60
c     
 60   continue
c     check for ', .'  **,  ^ and .^

      if (sym .ne. quote) go to 63
      if (lin(lpt(3)-1).ne.quote) then
c     .  not to admit " as a transposition operator 
C     .  (remove the equivalence ' ")
         go to 63
      endif
      i = lpt(3) - 2
      if (abs(lin(i)) .eq. blank) go to 90
      fin=quote
 61   rhs=1
      if ( eptover(1,psiz-1))  return
      rstk(pt)=310
      icall=4
c     *call* allops(quote) or allops(dot+quote)
      return
 62   pt=pt-1
      psym=sym
      call getsym

 63   continue
      if(sym.eq.hat) then
         op=dstar
      elseif(sym.eq.dot.and.char1.eq.hat) then
         call getsym
         op=dstar+dot
      elseif(sym.eq.star.and.char1.eq.star) then
         call getsym
         op=dstar
      elseif(sym.eq.dot.and.char1.eq.quote) then
         call getsym
         fin=dot+quote
         goto 61
      elseif(sym.eq.not.and.char1.ne.equal) then
         call error(276)
         return
      elseif(sym.eq.name.and.psym.eq.num) then
         i = lpt(3) - 2
         if (abs(lin(i)) .ne. blank) then
            ok=.false.
c     .     next line to restrict to mfile2sci compilation only
c     .     ok=(comp(1).ne.0.and.comp(3).eq.2) 
            if (ok) then
c     .        make 2m be evaluated as 2*m
               op=star
               goto 64
            else
c     .        issue an error
               lpt(2)=lpt(3)+1
               call error(276)
               if (err.gt.0) return
            endif
         endif
         goto 90
      else
         goto 90
      endif
      call getsym
 64   if ( eptover(1,psiz-1))  return
      rstk(pt) = 311
      pstk(pt) = op
      icall=3
c     *call* factor
      go to 01
 65   rstk(pt)=312
      fin=pstk(pt)
      rhs=2
      icall=4
c     *call* allops(dstar)
      return
 66   pt=pt-1
      goto 90

 90   return
c     
 99   call error(22)
      if (err .gt. 0) return
      return
      end

      subroutine name2var(id)
c     Copyright INRIA
      include '../stack.h'
c     given a variable name code in id, creates a string variable 
c     on the top of the stack
      integer id(nsiz)
      character*(nlgh) name
      integer iadr,sadr
c
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
      if (err1.gt.0) return
      top=top+1
      il=iadr(lstk(top))
      err=sadr(il+6+nlgh)-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif
      istk(il)=10
      istk(il+1)=1
      istk(il+2)=1
      istk(il+3)=0
      ilp=il+4
      istk(ilp)=1
      call namstr(id,istk(ilp+2),n,1)
      istk(ilp+1)=n+1
      lstk(top+1)=sadr(ilp+2+n)
      return
      end