File: parse.f

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (726 lines) | stat: -rw-r--r-- 18,066 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
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
      subroutine parse
c     ====================================================================
c     Scilab parsing function
c     ====================================================================
c     Copyright INRIA
      include '../stack.h'
      parameter (nz1=nsiz-1,nz2=nsiz-2)
      logical compil,eptover
c     
      logical iflag
      common /basbrk/ iflag
      integer semi,equal,eol,lparen,rparen,colon,dot
      integer blank,comma,left,right,less,great,not
      integer quote,percen
      integer name,num,insert,extrac
c     
      integer id(nsiz),ans(nsiz)
      integer pts,psym,excnt,p,r,topk
      integer pcount,strcnt,bcount,qcount,pchar
c
      integer otimer,ntimer,stimer,ismenu
      external stimer,ismenu
      save otimer
      data otimer/0/
c     
      data blank/40/,semi/43/,equal/50/,eol/99/,comma/52/,colon/44/
      data lparen/41/,rparen/42/,left/54/,right/55/,less/59/,great/60/
      data not/61/
      data quote/53/,percen/56/,dot/51/
      data name/1/,num/0/,insert/2/,extrac/3/
      data ans/672929546,nz1*673720360/
c     
      save job

c
      call xscion(inxsci)
 01   r = 0
      if(pt.gt.0) r=rstk(pt)
      if(ddt.eq.4) then
         write(buf(1:18),'(2i4,2i2,i6)') pt,r,icall,niv,err
         call basout(io,wte,' TOP    pt:'//buf(1:4)//' rstk(pt):'
     +        //buf(5:8)//' icall:'//buf(9:10)//' niv:'//buf(11:12)
     +        //' err:'//buf(13:18))
      endif
c     
      if(icall.eq.5) goto 88
      if(pt.gt.0) goto 86
      if(err.gt.0) goto 98

c     initialization
c-------------------
 05   sym = eol
      job=0
      if(rio.eq.-1) job=-1
      top = 0
      fin=0
      macr=0
      paus=0
      icall=0
      rio = rte
      lct(3) = 0
      lct(4) = 2
      lpt(1) = 1
      
      if(job.eq.-1) goto 13
c     
 10   if(sym.ne.eol) goto 15
      if(comp(1).eq.0) goto 12
      if(lin(lpt(4)+1).eq.eol) goto 88
c     
c     get a new line
c-------------------
 12   continue
      if(lct(4).le.-10) then 
         lct(4)=-lct(4)-11      
      else
         if (mod(lct(4)/2,2).eq.1) then
            call prompt(lct(4)/4)
            lct(1)=0
            if(paus.eq.0.and.rio.eq.rte) then
               if(pt.ne.0) then
                  call msgs(30,0)
                  pt=0
               endif
               if(top.ne.0) then
                  call msgs(31,0)
                  top=0
               endif
            endif
         endif
      endif
 13   continue
      call getlin(job)
      if(fin .eq. -1) then
c     Continuation line handling when scilab is called as a routine
         fun=99
         return
      endif
      job=0
      err = 0
c     
c     Beginning of a new statement, clause expression or command
c------------------------------------------------------------
 15   continue
      if (inxsci.eq.1) then
         ntimer=stimer()
         if (ntimer.ne.otimer) then
            call sxevents()
            otimer=ntimer
            if(ismenu().eq.1) goto 96
         endif
      endif
      r = 0
      if(pt.gt.0) r=rstk(pt)
      if(ddt.eq.4) then
         write(buf(1:20),'(3i4,i2,i6)') pt,r,top,niv,err
         call basout(io,wte,' parse  pt:'//buf(1:4)//' rstk(pt):'
     +        //buf(5:8)//' top:'//buf(9:12)//' niv:'//buf(13:14)
     +        //' err:'//buf(15:20))
      endif
c     
      excnt = 0
      if(.not.iflag) goto 18

c     Handling of pauses
 16   if ( eptover(1,psiz))  goto 98
      pstk(pt)=rio
      ids(2,pt)=top
      rio=rte
      rstk(pt)=701
      iflag=.false.
      fin=2
      if(lct(4).le.-10) then
         fin=-1
         lct(4)=-lct(4)-11 
      endif
c     *call* macro
      goto 88
c     pauses termination
 17   rio=pstk(pt)
      top=ids(2,pt)
      pt=pt-1
      goto 15

 18   lhs = 1
      call putid(id,ans)
c     
      call getsym
      if (sym.eq.right) call getsym
      if (sym.eq.colon) call getsym
      if (sym.eq.semi .or. sym.eq.comma .or. sym.eq.eol) goto 75
      if (sym.eq.name) goto 20
      if (sym.eq.left) goto 40
      goto 60
c     
c     lhs begins with name
c-------------------------
 20   call comand(syn)
      if (err .gt. 0) goto 98
      if (fun .eq. 99) return
      if (fun .ne. 0) goto 93
      if (fin .lt. 0) goto 80
      if (fin .eq. 2) goto 88
      if (fin .eq. 3) goto 16
      if (fin .eq. 4) goto 05
      if (fin .gt. 0) goto 75
 21   rhs = 0
c      fin=0
c      call funtab(syn,fin,1)
      fin=-5
c IL y a p avec fin=-5 (on ne trouve pas les macros parce que l'on ne
c veut pas que les macros sans arg soient vues comme des commandes
c mais pourquoi pas il suffirait de dire que pour visualiser une macro
c il faut faire disp()
      fun=0
      call funs(syn)
      if (fin .gt. 0) then
c        name est le nom d'une primitive
         if(char1.eq.equal) then
            call putid(ids(1,pt+1),syn)
            call error(25)
            goto 98
         endif
c        name is a function, must be rhs
         goto 60
      endif
c     
c     peek one character ahead
      if (char1.eq.semi .or. char1.eq.comma .or. char1.eq.eol)
     $     call putid(id,syn)
      if (char1 .eq. equal) goto 25
      if (char1 .eq. lparen) goto 30
      goto 60
c     
c     lhs is simple variable
c---------------------------
 25   call putid(id,syn)
      lpts=lpt(2)
      call getsym
      if(char1.eq.equal) then
c     logical equality
         lpt(4)=lpts
         lpt(2)=lpts
         lpt(3)=lpts
         call putid(id,ans)
         char1=blank
         sym=blank
      endif
      call getsym
      goto 60
c     
c     lhs is name(...)
c---------------------
 30   lpt(5) = lpt(4)
      call putid(id,syn)
c     
c     looking for equal
      pcount=0
      strcnt=0
      bcount=0
 31   psym=sym
      call getsym
      if(strcnt.ne.0) then
         if(sym.eq.eol) then
            call error(3)
            goto 98
         endif
         if(sym.eq.quote) then
            qcount=0
 311        qcount=qcount+1
            if(abs(char1).ne.quote) goto 312
            call getsym
            goto 311
 312        continue
            if(2*int(qcount/2).ne.qcount)  strcnt=0
         endif
      else if(sym.eq.lparen) then
         pcount=pcount+1
      else if(sym.eq.rparen) then
         pcount=pcount-1
         if(pcount.lt.0) then
            call error(2)
            goto 98
         endif
      else if(sym.eq.quote) then
c     .  check if transpose or beginning of a string
         pchar=lin(lpt(3)-2)
         if(abs(pchar).eq.blank) then
            strcnt=1
         elseif(psym.ne.num.and.psym.ne.name.and.psym.ne.rparen.and.
     $           psym.ne.right.and.psym.ne.dot.and.psym.ne.quote) then
            strcnt=1
         endif

c         if(psym.ne.num.and.psym.ne.name.and.psym.ne.rparen.and.
c     $        psym.ne.right.and.psym.ne.dot.and.psym.ne.quote)
c     $        strcnt=1
c         if (bcount.ne.0) then
c            pchar=lin(lpt(3)-2)
c            if(abs(pchar).eq.blank) strcnt=1
c         endif
      else if(sym.eq.left) then
         bcount=bcount+1
      else if(sym.eq.right) then
         bcount=bcount-1
         if(bcount.lt.0) then
            call error(2)
            goto 98
         endif
      else if(pcount.eq.0) then
c         if(bcount.ne.0) then
c            call error(2)
c            goto 98
c         endif
         if(sym.eq.equal) then
            if(char1.eq.equal) then
               call getsym
            else
               if(psym.ne.less.and.psym.ne.great.and.
     $              psym.ne.not)  goto 32
            endif
         endif
         if(sym.eq.eol .or. sym.eq.comma .or. sym.eq.semi) goto 50
c     .  next line for recursive index
         if(sym.eq.lparen) goto 31
      else if(sym.eq.eol) then
         if(bcount.eq.0) then
            call error(3)
            goto 98
         else
            if(lpt(4).eq.lpt(6))  then
               call getlin(1)
               if(err.gt.0) goto 98
            else
               lpt(4)=lpt(4)+1
               call getsym
            endif
         endif
      endif
      goto 31
c     
 32   lpt(4)=lpt(5)
      icount=0
      char1=lparen
      call getsym
 33   call getsym
      excnt = excnt+1
      if ( eptover(1,psiz)) goto 98
      call putid(ids(1,pt), id)
      pstk(pt) = excnt+1000*icount
      rstk(pt) = 702
c     *call* expr
      goto 81
 35   continue

      call putid(id,ids(1,pt))
      icount=int(pstk(pt)/1000)
      excnt = pstk(pt)-1000*icount
      pt = pt-1
      if (sym .eq. comma) goto 33
      if (sym .ne. rparen) then
         call error(3)
         if (err .gt. 0) goto 98
      endif
      if (sym .eq. rparen) call getsym
c     next lines for recursive index
      if(sym.eq.lparen) then

         if(excnt.gt.1) then
c           call error(3)
c           return
            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

         endif
         excnt=0
         icount=icount+1
         goto 33
      endif
      if(icount.gt.0) then
         if(comp(1).eq.0) then
c     .     form  list with individual indexes
            call mkindx(icount+1,excnt)
            if(err.gt.0) return
         else
            if (compil(19,icount+1,excnt,0,0)) then 
               if (err.gt.0) return
            endif
         endif
         excnt=1
      endif
c     end of code for recursive index
      goto 60
c     
c     multiple lhs
c-----------------
 40   lpt(5) = lpt(4)
      pts = pt
      call getsym
 41   if (sym .ne. name) goto 43
      call putid(id,syn)
      call getsym
      if (sym .eq. right) goto 42
      if (sym .eq. comma) call getsym
      if ( eptover(1,psiz)) goto 98
      lhs = lhs+1
      pstk(pt) = 0
      rstk(pt) = 0
      call putid(ids(1,pt),id)
      goto 41
 42   call getsym
      if (sym .eq. equal) then
         if(char1.eq.equal) goto 43
         goto 60
      endif
 43   lpt(4) = lpt(5)
      pt = pts
      lhs = 1
      sym = left
      char1 = lin(lpt(4)-1)
      call putid(id,ans)
      goto 60
c     
c     
c     lhs is really rhs
c-----------------------
 50   lpt(4)=lpt(5)
      char1=lparen
      sym=name
      call putid(syn,id)
      call putid(id,ans)
      goto 61
c     
c     lhs finished, start rhs
c----------------------------
 60   if (sym .eq. equal) call getsym
c      fun=0
c      if(sym.eq.name) then
c     check if name is a function
c         fin=-2
c         call funs(syn)
c      endif

 61   if ( eptover(1,psiz))  goto 98
      call putid(ids(1,pt),id)

      pstk(pt) = excnt
      rstk(pt) = 703
c     *call* expr
      goto 81
 65   continue
      if (rstk(pt-lhs).eq.313) then 
c     store  new variable as "named" at the top of the stack
         if (sym.eq.rparen .or. sym.eq.comma) then
            call mrknmd()
            if(err.gt.0) goto 98
            goto 83
         else
            call error(40)
            goto 98
         endif
      endif
      if (sym.eq.semi .or. sym.eq.comma .or. sym.eq.eol) goto 70
      call error(40)
      goto 98
c     
c     store results
c-------------------
 70   rhs = pstk(pt)
      if(err1.ne.0) goto 74
      if(rhs.eq.0) goto 72
      fin=-3
      call stackg(ids(1,pt))
      if (err .gt. 0) goto 98
      rhs=rhs+2
      pstk(pt)=lhs
      rstk(pt)=704
      fin=insert
c     *call* allops(insert)
      goto 91
 71   lhs=pstk(pt)
 72   call stackp(ids(1,pt),0)
      if (err .gt. 0) goto 98
c     topk points on the newly saved variable
      topk=fin
c     print if required
c----------------------
      if(lct(4).lt.0.or.fin.eq.0) goto 74
      if(.not.((sym.ne.semi.and.lct(3).eq.0).or.
     &     (sym.eq.semi.and.lct(3).eq.1))) goto 74
 73   call print(ids(1,pt),topk,wte)
      if (err .gt. 0) goto 98
      if(topk.eq.0) goto 74
c     overloaded display, call a macro
      if ( eptover(1,psiz))  goto 98
      rstk(pt)=708
      pstk(pt)=sym
      ids(1,pt)=sym
      if(fun.eq.0) goto 88
      goto 85
 731  continue
      sym=pstk(pt)
      pt=pt-1
      goto 73
c     
 74   pt = pt-1
      lhs = lhs-1
      if (lhs .gt. 0) goto 70

c     
c     finish statement
c---------------------
 75   fin = 0
      p = 0
      r = 0
      if (pt .gt. 0) p = pstk(pt)
      if (pt .gt. 0) r = rstk(pt)
      if (ddt .eq. 4) then
         write(buf(1:22),'(4i4,3i2)') pt,r,p,lpt(1),niv,macr,paus
         call basout(io,wte,
     +        ' finish pt:'//buf(1:4)//' rstk(pt):'//buf(5:8)//
     +        ' pstk(pt):'//buf(9:12)//' lpt(1):'//buf(13:16)//
     +        ' niv:'//buf(17:18)//' macr:'//buf(19:20)//
     +        ' paus:'//buf(21:22))
      endif
      if(err1.ne.0) then
         if(rstk(pt).eq.502.and.rstk(pt-1).eq.903) then
c     catched and continue on error in an execstr instruction
            goto 88
         endif
         if(err2.eq.0) err2=err1
         err1=0
         imode=abs(errct/100000)
         if(imode-8*int(imode/8).eq.2) iflag=.true.
      endif
      toperr=top
c     fin instruction
      if(sym.ne.eol) goto 15
c     gestion des points d'arrets dynamiques
      if(wmac.ne.0) then
         call whatln(lpt(1),lpt(2)-1,lpt(6),nlc,l1,ifin)
         
         do 76 ibpt=lgptrs(wmac),lgptrs(wmac+1)-1
            if(lct(8)-nlc.eq.bptlg(ibpt)) then
               call cvname(macnms(1,wmac),buf(1:nlgh),1)
               write(buf(nlgh+2:nlgh+7),'(i5)') lct(8)-nlc
               call msgs(32,0)
               call cvstr(ifin-l1+1,lin(l1),buf,1)
               call basout(io,wte,buf(1:ifin-l1+1))
               iflag=.true.
               goto 77
            endif
 76      continue
      endif
 77   continue
c     
      if(comp(1).ne.0) call seteol
c     fin ligne
      if(int(r/100).ne.8) goto 10
c     fin d'une instruction dans une clause
      if(comp(1).ne.0) then
         k=lpt(6)
         if(lin(k-1).eq.eol.and.lin(k).eq.eol) then
            call error(47)
            goto 98
         endif
      endif
      if(lpt(4).eq.lpt(6))  then
         call getlin(1)
      else
         lpt(4)=lpt(4)+1
         call getsym
      endif
      goto 15
c     
c     simulate recursion
c-----------------------
 80   icall=0
      call clause
      if (err .gt. 0) goto 98
      goto(81,82,83,91,88,90,15,80,85),icall
      if (pt .le. 0) goto 15
      r = rstk(pt)/100
      goto(81,82,83,91,88,90,92,80,85),r
      goto 99
c     
 81   icall=0
      call expr
      if (err .gt. 0) goto 98
      goto(81,82,83,91,88,90,15,80,85),icall
      r = rstk(pt)/100
      goto(81,82,83,91,88,90,92,80,85),r
      goto 99
c     
 82   icall=0
      call terme
      if (err .gt. 0) goto 98
      goto(81,82,83,91,88,90,15,80,85),icall
      r = rstk(pt)/100
      goto(81,82,83,91,88,90,92,80,85),r
      goto 99
c     
 83   icall=0
      call fact
      if (err .gt. 0) goto 98
      goto(81,82,83,91,88,90,15,80,85),icall
      r = rstk(pt)/100
      goto(81,82,83,91,88,90,92,80,85),r
      goto 99
c     
 85   icall=0
      if(err1.ne.0) then
         if(int(rstk(pt)/100).eq.9) then
            if(rstk(pt).eq.901.or.rstk(pt).eq.904) then
c              *call* matfns
               return
            elseif(rstk(pt).ne.903) then
               pt=pt-1
               goto 86
            endif
         else
            goto 86
         endif
      endif
c     compilation matfns: <100*fun rhs lhs fin>
      if (compil(100*fun,rhs,lhs,fin,0)) then 
         if (err.gt.0) goto 98 
         goto 86
      else
c     *call* matfns
         return
      endif
 86   if (err .gt. 0) goto 98
      goto(81,82,83,91,88,90,15,80,85),icall
      r = rstk(pt)/100
      goto(81,82,83,91,88,90,92,80,85),r
      goto 99
      
c     
 88   icall=0
      call macro
      if (err .gt. 0) goto 98
      goto(81,82,83,91,88,90,10,80,85),icall
      r = rstk(pt)/100
      goto(81,82,83,91,88,90,92,80,85,89),r
      goto 99
 89   fun=99
      return
c     
 90   icall=0
      call  run
      if (err .gt. 0) goto 98
      if (fun .eq. 99) return
c     last label is used to handle return from abort
      goto(81,82,83,91,88,90,15,80,85,05),icall
      r = rstk(pt)/100
      goto(81,82,83,91,88,90,92,80,85),r
      goto 99
c     
 91   icall=0
      call allops
      if (err .gt. 0) goto 98
      goto(81,82,83,91,88,90,15,80,85),icall
      r = rstk(pt)/100
      goto(81,82,83,91,88,90,92,80,85),r
      goto 99
c     
 92   goto(17,35,65,71,65,97,94,731) rstk(pt)-700
      goto 99
c     
 93   continue
c     command like function and macro call
      if ( eptover(1,psiz)) goto 98
      pstk(pt)=1
      call putid(ids(1,pt),ans)
      rstk(pt)=707
      if (fun .gt. 0)  then
c        *call* matfns
         goto 85
      else
         if (comp(1).ne.0)  then
            rhs=rhs+1
            fin=extrac
c           *call* allops(extrac)
            goto 91
         else
            fin=lstk(fin)
c           *call* macro
            goto 88
         endif
      endif
 94   goto 71
c
 96   continue
c     asynchronous events handling
      call getmen(buf,lb,nentry)
      call bexec(buf(1:lb),lb,ierr)
      if(ierr.ne.0) goto 15
      if ( eptover(1,psiz)) goto 98
      pstk(pt)=top
      rstk(pt)=706

c     *call* macro
      goto 88
 97   top=pstk(pt)-1
      pt=pt-1
      goto 15
      
 98   continue
c     error recovery
c-------------------
      imode=abs(errct)/100000
      imode=imode-8*int(imode/8)
      if(imode.eq.3) then
         fun=99
         return
      endif
c     
c     error in an external (niv), during compilation (comp) or in a pause
      if(pt.ne.0) then
         if(rstk(pt).eq.503.and.rio.eq.rte) then
            comp(1)=0
            goto 12
         endif
c     added 16/04/97
         if(err1.ne.0.and.rstk(pt).eq.502) then
c     catched error while compiling
            goto 88
         endif
      endif
c     error in an external
      if(niv.gt.0) then
         return
      else
c     error in a  pause
         comp(1)=0
         goto 05
      endif
c     
 99   call error(22)
      goto 01
c

      end