-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.f
1971 lines (1966 loc) · 62.2 KB
/
compiler.f
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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
C*********************************************************************72
PROGRAM URCLCOMPILE
IMPLICIT NONE
C PROGRAM TO COMPILE FORTRAN TO URCL
CHARACTER (LEN = 72) LINE
CHARACTER (LEN = 5) LABEL
CHARACTER (LEN = 6) VARS(64)
CHARACTER (LEN = 72) TMPSTR
CHARACTER (LEN = 72) TMPSR2
CHARACTER (LEN = 72) TMPSR3
CHARACTER (LEN = 72) TMPSR4
CHARACTER (LEN = 72) TMPSR5
CHARACTER (LEN = 72) VARDO(16)
CHARACTER (LEN = 72) EACHDO(16)
INTEGER VDOPTR
CHARACTER (LEN = 8) FUNCS(99)
INTEGER FNTYPE(99), FNARGS(99), VARADR(64), VARTYP(64), TYPES(64)
INTEGER VARSZE(64)
INTEGER N, LINEN, TEMP, TEMP2, TEMP3, CRTVAR, VARPTR
LOGICAL IMPLIC, ISPTR(64)
C SHUNTING YARD
INTEGER TMPI, TMPI2, TMPI3, OUT(128), STACK(128), OP, SP, TYPP
INTEGER RETTYP, INIF, IFNUM, IFTBL(16), IFPTR, DEPTH
REAL TMPR
LOGICAL NALLOW, IFUNCS(99), COMEXT, TOP, DECBLK
CHARACTER (LEN = 6) ARGS(32)
INTEGER ARGPTR
INTEGER TMPARR(32)
INTEGER TMPPTR
ARGPTR = 0
IFPTR = 0
INIF = 0
IFNUM = 0
CRTVAR = 0
LINEN = 0
VARPTR = 1
VDOPTR = 0
DECBLK = .FALSE.
IMPLIC = .TRUE.
COMEXT = .FALSE.
TOP = .TRUE.
OPEN (UNIT=8, FILE='SOURCE.F', ACTION='READ')
OPEN (UNIT=9, FILE='OUTPUT.URCL', ACTION='WRITE')
WRITE (9, '(A)') 'BITS 32', 'MINHEAP 1024', 'MINSTACK 32', ''
TEMP = 1
999 IFUNCS(TEMP) = .FALSE.
TEMP = TEMP + 1
IF (TEMP.NE.100) GOTO 999
GOTO 50000
1000 TOP = .FALSE.
1002 IF (INIF.EQ.2) THEN
WRITE (TMPSTR, *) IFNUM-1
WRITE (9, '(A)') '.IF_END_'//TRIM(ADJUSTL(TMPSTR))
INIF = 0
ELSE IF (INIF.EQ.3) THEN
LINE = EACHDO(VDOPTR)
TEMP2 = 7003
GOTO 20001
END IF
READ (8, '(A)', ERR=1, END=2, IOSTAT=N) LINE
LINEN = LINEN + 1
C WRITE (*, '(A)') LINE
1111 IF (LINE.EQ.'') GOTO 1002
IF (LINE(:1).EQ.'C') GOTO 1002
IF (LINE(6:6).NE.' ') GOTO 3
IF (LINE(:5).NE.' ') GOTO 1001
2001 LINE = ADJUSTL(LINE(6:))
IF (LINE(:8).EQ.'CONTINUE') GOTO 1000
IF (LINE(:4).EQ.'STOP') GOTO 1003
IF (LINE(:9).EQ.'CHARACTER') GOTO 3000
IF (LINE(:7).EQ.'INTEGER') GOTO 3001
IF (LINE(:4).EQ.'REAL') GOTO 3003
IF (LINE(:7).EQ.'LOGICAL') GOTO 3004
IF (LINE(:13).EQ.'IMPLICIT NONE') THEN
IMPLIC = .FALSE.
GOTO 1000
END IF
IF (DECBLK) GOTO 8500
8501 IF (LINE(:4).EQ.'GOTO') GOTO 4000
IF (LINE(:5).EQ.'GO TO') GOTO 4000
IF (LINE(:3).EQ.'IF ') GOTO 5000
IF (LINE(:3).EQ.'IF(') GOTO 5000
IF (LINE(:7).EQ.'ELSE IF') GOTO 5600
IF (LINE(:4).EQ.'ELSE') GOTO 5500
IF (LINE(:3).EQ.'DO ') GOTO 7000
IF (LINE(:5).EQ.'WRITE') GOTO 6000
IF (LINE(:3).EQ.'END') GOTO 5700
IF (LINE(:4).EQ.'EXIT') GOTO 7100
IF (LINE(:10).EQ.'SUBROUTINE') GOTO 8000
IF (LINE(:4).EQ.'CALL') GOTO 8600
IF (LINE(:7).EQ.'PROGRAM') THEN
IF (.NOT.TOP) WRITE (9, '(A)') '.__MAIN'
IMPLIC = .TRUE.
VARPTR = 1
VARS(VARPTR) = ''
IFPTR = IFPTR + 1
IFTBL(IFPTR) = 1000000
DECBLK = .FALSE.
GOTO 1000
END IF
IF (LINE(:5).EQ.'PRINT') THEN
TEMP = INDEX(LINE,' ') + 1
LINE = LINE(TEMP:)
IF (LINE(:5).EQ.'''(A)''') THEN
TEMP = INDEX(LINE,',') + 1
LINE = LINE(TEMP:)
GOTO 6011
END IF
IF (LINE(:1).NE.'*') GOTO 4
TEMP = INDEX(LINE,',') + 1
LINE = LINE(TEMP:)
WRITE (9, '(A)') 'MOV R6 SP','PSH @MAX'
COMEXT = .TRUE.
TEMP2 = 6210
GOTO 20001
END IF
TEMP3 = 0
GOTO 3002
9999 CLOSE (8)
CLOSE (9)
STOP
CALCULATE LINE LABELS
1001 LABEL = ADJUSTL(LINE(:5))
READ (LABEL, *) TEMP
TEMP2 = 2000000000
IF(IFTBL(IFPTR).GT.TEMP2.AND.TEMP.EQ.MOD(IFTBL(IFPTR),TEMP2))THEN
TMPSR4 = LABEL
INIF = 3
END IF
WRITE (9, '(A)') '.LABEL_'//TRIM(LABEL)
GOTO 2001
C STOP
1003 WRITE (9, '(A)') 'HLT'
GOTO 1000
CHARACTER/STRING VARIABLES
3000 IF (TRIM(LINE(10:)).EQ.'') GOTO 4
LINE = ADJUSTL(LINE(10:))
TEMP = 1
IF (LINE(1:4).EQ.'(LEN') GOTO 3010
IF (LINE(1:1).EQ.'*') GOTO 3009
4010 VARS(VARPTR) = LINE(:6)
VARADR(VARPTR) = CRTVAR
TEMP2 = TEMP + 2000
VARTYP(VARPTR) = TEMP2
ISPTR(VARPTR) = .FALSE.
VARPTR = VARPTR + 1
VARS(VARPTR) = ''
CRTVAR = CRTVAR + TEMP
GOTO 1000
3009 LINE = ' ='//LINE(2:)
3010 LINE = LINE(5:)
LINE = ADJUSTL(LINE)
IF (LINE(1:1).NE.'=') GOTO 4
LINE(1:) = LINE(2:)
LINE = ADJUSTL(LINE)
TEMP = INDEX(LINE,')')-1
IF (TEMP.EQ.-1) TEMP = INDEX(LINE, ' ')-1
TMPSTR = LINE(1:TEMP)
TEMP = TEMP + 2
LINE = LINE(TEMP:)
LINE = ADJUSTL(LINE)
READ (TMPSTR, *) TEMP
GOTO 4010
C INTEGER VARIABLES
3001 LINE = LINE(8:)
IF (LINE(:1).EQ.'*') THEN
TEMP = INDEX(LINE, ' ')
TMPSTR = LINE(2:TEMP)
LINE = LINE(TEMP:)
READ (TMPSTR, *) TEMP2
IF (TEMP2.GT.4) GOTO 6
ELSE
TEMP2 = 4
END IF
3011 IF (INDEX(LINE, ',').NE.0) THEN
TEMP = INDEX(LINE, ',') + 1
TMPSTR = LINE(TEMP:)
TEMP = TEMP - 2
LINE = ADJUSTL(LINE(:TEMP))
ELSE
TMPSTR = ''
LINE = ADJUSTL(LINE)
END IF
TEMP = INDEX(LINE, ' ')
IF (INDEX(LINE, '(').NE.0) TEMP = MIN(TEMP, INDEX(LINE, '('))
TEMP = TEMP - 1
VARS(VARPTR) = LINE(:TEMP)
TEMP = TEMP + 1
LINE = LINE(TEMP:)
TEMP = 1
IF (LINE(:1).EQ.'(') THEN
TEMP = INDEX(LINE, ')') - 1
TMPSTR = LINE(2:TEMP)
READ (TMPSTR, *) TEMP
END IF
VARADR(VARPTR) = CRTVAR
VARTYP(VARPTR) = 999 + TEMP
ISPTR(VARPTR) = .FALSE.
VARSZE(VARPTR) = TEMP2
VARPTR = VARPTR + 1
VARS(VARPTR) = ''
CRTVAR = CRTVAR + TEMP
IF (TMPSTR.NE.'') THEN
LINE = TMPSTR
GOTO 3011
END IF
GOTO 1000
C REAL VARIABLES
3003 LINE = LINE(5:)
3013 IF (INDEX(LINE, ',').NE.0) THEN
TEMP = INDEX(LINE, ',') + 1
TMPSTR = LINE(TEMP:)
TEMP = TEMP - 2
LINE = ADJUSTL(LINE(:TEMP))
ELSE
TMPSTR = ''
LINE = ADJUSTL(LINE)
END IF
TEMP = INDEX(LINE, ' ')
IF (INDEX(LINE, '(').NE.0) TEMP = MIN(TEMP, INDEX(LINE, '('))
TEMP = TEMP - 1
VARS(VARPTR) = LINE(:TEMP)
TEMP = TEMP + 1
LINE = LINE(TEMP:)
TEMP = 1
IF (LINE(:1).EQ.'(') THEN
TEMP = INDEX(LINE, ')') - 1
TMPSTR = LINE(2:TEMP)
READ (TMPSTR, *) TEMP
END IF
VARADR(VARPTR) = CRTVAR
VARTYP(VARPTR) = 2999 + TEMP
ISPTR(VARPTR) = .FALSE.
VARPTR = VARPTR + 1
VARS(VARPTR) = ''
CRTVAR = CRTVAR + TEMP
IF (TMPSTR.NE.'') THEN
LINE = TMPSTR
GOTO 3013
END IF
GOTO 1000
C LOGICAL VARIABLES
3004 LINE = LINE(8:)
IF (LINE(:1).EQ.'*') THEN
TEMP = INDEX(LINE, ' ')
TMPSTR = LINE(2:TEMP)
LINE = LINE(TEMP:)
READ (TMPSTR, *) TEMP2
IF (TEMP2.GT.4) GOTO 6
ELSE
TEMP2 = 4
END IF
3014 IF (INDEX(LINE, ',').NE.0) THEN
TEMP = INDEX(LINE, ',') + 1
TMPSTR = LINE(TEMP:)
TEMP = TEMP - 2
LINE = ADJUSTL(LINE(:TEMP))
ELSE
TMPSTR = ''
LINE = ADJUSTL(LINE)
END IF
TEMP = INDEX(LINE, ' ')
IF (INDEX(LINE, '(').NE.0) TEMP = MIN(TEMP, INDEX(LINE, '('))
TEMP = TEMP - 1
VARS(VARPTR) = LINE(:TEMP)
TEMP = TEMP + 1
LINE = LINE(TEMP:)
TEMP = 1
IF (LINE(:1).EQ.'(') THEN
TEMP = INDEX(LINE, ')') - 1
TMPSTR = LINE(2:TEMP)
READ (TMPSTR, *) TEMP
END IF
VARADR(VARPTR) = CRTVAR
VARTYP(VARPTR) = 3999 + TEMP
ISPTR(VARPTR) = .FALSE.
VARSZE(VARPTR) = TEMP2
VARPTR = VARPTR + 1
VARS(VARPTR) = ''
CRTVAR = CRTVAR + TEMP
IF (TMPSTR.NE.'') THEN
LINE = TMPSTR
GOTO 3014
END IF
GOTO 1000
C ASSIGNMENT
3002 TEMP = INDEX(LINE, '=')-1
TEMP2 = 0
IF (INDEX(LINE, '(').NE.0.AND.INDEX(LINE, '(').LT.TEMP) THEN
TEMP = INDEX(LINE, '(')-1
TEMP2 = 1
END IF
TMPSTR = LINE(:TEMP)
N = 0
3102 N = N + 1
TMPSR2 = VARS(N)
IF (N.EQ.65.OR.TMPSR2.EQ.'') THEN
IF (.NOT.IMPLIC) GOTO 4
ISPTR(VARPTR) = .FALSE.
VARS(VARPTR) = TMPSTR
VARADR(VARPTR) = CRTVAR
IF (TMPSTR(:1).GT.'N'.OR.TMPSTR(:1).LT.'I') THEN
VARTYP(VARPTR) = 3000
ELSE
VARTYP(VARPTR) = 1000
END IF
VARSZE(VARPTR) = 4
N = VARPTR
CRTVAR = CRTVAR + 1
VARPTR = VARPTR + 1
VARS(VARPTR) = ''
GOTO 3103
END IF
IF (TMPSR2(1:6).NE.TMPSTR(1:6)) GOTO 3102
3103 TEMP = TEMP + 2
LINE = LINE(TEMP:)
TEMP = 0
IF (TEMP2.EQ.1) THEN
TEMP2 = INDEX(LINE, ')')-1
TMPSTR = LINE(:TEMP2)
IF (TMPSTR(:1).LT.'0'.OR.TMPSTR(:1).GT.'9') THEN
TEMP = 1000000
TMPSR3 = LINE
LINE = TMPSTR
TEMP2 = 3203
GOTO 20001
ELSE
READ (TMPSTR, *) TEMP
END IF
TEMP2 = INDEX(LINE, '=')+1
LINE = LINE(TEMP2:)
END IF
TEMP2 = 3202
GOTO 20001
3203 LINE = TMPSR3
TEMP2 = INDEX(LINE, '=')+1
LINE = LINE(TEMP2:)
TEMP2 = 3202
GOTO 20001
3202 TEMP2 = VARTYP(N)
IF (RETTYP.EQ.1.AND.TEMP2/1000.EQ.3) THEN
WRITE (9, '(A)') 'POP R1', 'BSL R1 R1 16', 'PSH R1'
ELSE IF (RETTYP.NE.TEMP2/1000) THEN
WRITE (TMPSTR, *) LINEN
WRITE (*, '(A)') 'ON LINE '//TRIM(ADJUSTL(TMPSTR))
WRITE (*, '(A)') 'INVALID TYPES IN ASSIGNMENT'
STOP
END IF
IF (TEMP2.GE.3000.OR.TEMP2.LT.2000) GOTO 3212
IF (TEMP3.NE.0) GOTO 4
WRITE (TMPSTR, *) MOD(TEMP2, 1000)
WRITE (TMPSR2, *) VARADR(N)
WRITE (9, '(A)') 'LOD R1 SP', 'IMM R3 '//TRIM(ADJUSTL(TMPSTR))
IF (ISPTR(N)) THEN
WRITE (9, '(A)') 'LOD R2 M'//TRIM(ADJUSTL(TMPSTR))
ELSE
WRITE (9, '(A)') 'IMM R2 M'//TRIM(ADJUSTL(TMPSR2))
END IF
WRITE (9, '(A)') 'ADD R4 SP R1'
WRITE (9, '(A)')'INC SP R4','CPY R2 R4','DEC R3 R3', 'DEC R4 R4'
WRITE (9, '(A)')'INC R2 R2','DEC R1 R1','BRZ ~+6 R3','BNZ ~-6 R1'
WRITE (9, '(A)') 'STR R2 32','INC R2 R2','DEC R3 R3','BNZ ~-3 R3'
IF (TEMP3.NE.0) GOTO 7001
GOTO 1000
3212 IF (TEMP.NE.1000000) THEN
WRITE (TMPSTR, *) VARADR(N) + TEMP
IF (ISPTR(N)) WRITE (TMPSTR, *) VARADR(N)
WRITE (9, '(A)') 'POP R1'
IF (VARSZE(N).NE.4) THEN
WRITE (TMPSR2, *) 2**(8*VARSZE(N))-1
WRITE (9, '(A)') 'AND R1 R1 '//TRIM(ADJUSTL(TMPSR2))
END IF
IF (ISPTR(N)) THEN
WRITE (9, '(A)') 'LOD R2 M'//TRIM(ADJUSTL(TMPSTR))
WRITE (TMPSR2, *) TEMP
TMPSR2 = ADJUSTL(TMPSR2)
WRITE (9, '(A)') 'LSTR R2 '//TRIM(TMPSR2)//' R1'
ELSE
WRITE (9, '(A)') 'STR M'//TRIM(ADJUSTL(TMPSTR))//' R1'
END IF
IF (TEMP3.NE.0) THEN
TMPSR5 = 'LOD R1 M'//TRIM(ADJUSTL(TMPSTR))
IF (ISPTR(N)) TMPSR5 = TRIM(TMPSR5)//CHAR(10)//'LOD R1 R1'
TMPSR5 = TRIM(TMPSR5)//CHAR(10)//'ADD R1 R1 R8'//CHAR(10)
TMPSR5 =TRIM(TMPSR5)//'STR M'//TRIM(ADJUSTL(TMPSTR))//' R1'
VDOPTR = VDOPTR + 1
VARDO(VDOPTR) = TMPSR5
END IF
ELSE
WRITE (TMPSTR, *) VARADR(N)
WRITE (9, '(A)') 'POP R1', 'POP R2'
IF (VARSZE(N).NE.4) THEN
WRITE (TMPSR2, *) 2**(8*VARSZE(N))-1
WRITE (9, '(A)') 'AND R1 R1 '//TMPSR2
END IF
WRITE (9, '(A)') 'LSTR M'//TRIM(ADJUSTL(TMPSTR))//' R2 R1'
IF (TEMP3.NE.0) THEN
TMPSR5 = 'LLOD R1 M'//TRIM(ADJUSTL(TMPSTR))//' R2'
TMPSR5 = TMPSR5//CHAR(10)//'ADD R1 R1 R8'//CHAR(10)
TMPSR5 = TMPSR5//'LSTR M'//TRIM(ADJUSTL(TMPSTR))//' R2 R1'
VDOPTR = VDOPTR + 1
VARDO(VDOPTR) = TMPSR5
END IF
END IF
IF (TEMP3.NE.0) GOTO 7001
GOTO 1000
C GOTO
4000 LINE = ADJUSTL(LINE(5:))
IF (LINE(:1).EQ.'O') LINE = ADJUSTL(LINE(2:))
WRITE (9, '(A)') 'JMP .LABEL_'//TRIM(LINE)
GOTO 1000
C IF
5000 LINE = ADJUSTL(LINE(3:))
IF (LINE(1:1).NE.'(') GOTO 4
LINE = ADJUSTL(LINE(2:))
C ARITHMETIC IF
TEMP2 = 5200
C 0 = not in logical if
C 1 = inside if calc
C 2 = inside logical if
INIF = 1
GOTO 20001
5200 INIF = 0
WRITE (9, '(A)') 'POP R1'
IF (RETTYP.NE.1) GOTO 5300
TEMP = INDEX(LINE,',')-1
IF (TEMP.LE.0) GOTO 4
TMPSTR = ADJUSTL(LINE(:TEMP))
TEMP = TEMP + 2
LINE = LINE(TEMP:)
WRITE (9, '(A)') '//','BRN .LABEL_'//TRIM(TMPSTR)//' R1'
TEMP = INDEX(LINE,',')-1
IF (TEMP.LE.0) GOTO 4
TMPSTR = ADJUSTL(LINE(:TEMP))
TEMP = TEMP + 2
LINE = LINE(TEMP:)
WRITE (9, '(A)') 'BRZ .LABEL_'//TRIM(TMPSTR)//' R1'
LINE = ADJUSTL(LINE)
IF (LINE(1:1).EQ.' ') GOTO 4
WRITE (9, '(A)') 'JMP .LABEL_'//TRIM(LINE)
GOTO 1000
C LOGICAL IF
5300 IF (RETTYP.NE.4) WRITE (*, '(A)') 'INVALID RETURN TYPE FOR IF'
IF (TRIM(ADJUSTL(LINE)).EQ.'THEN') GOTO 5400
WRITE (TMPSTR, *) IFNUM
WRITE (9, '(A)') 'BRZ .IF_END_'//TRIM(ADJUSTL(TMPSTR))//' R1'
IFNUM = IFNUM + 1
LINE = ' '//LINE(:66)
INIF = 2
GOTO 1111
C BLOCK IF
5400 IFPTR = IFPTR + 1
IFTBL(IFPTR) = IFNUM * 1000
WRITE (TMPSTR, *) IFNUM
WRITE (9, '(A)') 'BRZ .IF_END_'//TRIM(ADJUSTL(TMPSTR))//'_0 R1'
IFNUM = IFNUM + 1
GOTO 1000
C ELSE
5500 WRITE (TMPSTR, *) IFTBL(IFPTR)/1000
TMPSTR = ADJUSTL(TMPSTR)
WRITE (9, '(A)') 'JMP .IF_END_'//TRIM(TMPSTR)//'_REAL'
TEMP = IFTBL(IFPTR) - IFTBL(IFPTR)/1000*1000
WRITE (TMPSR2, *) TEMP
TMPSR2 = ADJUSTL(TMPSR2)
WRITE (9, '(A)') '.IF_END_'//TRIM(TMPSTR)//'_'//TRIM(TMPSR2)
TEMP = TEMP + 1
IFTBL(IFPTR) = IFTBL(IFPTR)/1000*1000 + TEMP
GOTO 1000
C ELSE IF
5600 WRITE (TMPSTR, *) IFTBL(IFPTR)/1000
TMPSTR = ADJUSTL(TMPSTR)
WRITE (9, '(A)') 'JMP .IF_END_'//TRIM(TMPSTR)//'_REAL'
TEMP = IFTBL(IFPTR) - IFTBL(IFPTR)/1000*1000
WRITE (TMPSR2, *) TEMP
TMPSR2 = ADJUSTL(TMPSR2)
WRITE (9, '(A)') '.IF_END_'//TRIM(TMPSTR)//'_'//TRIM(TMPSR2)
TEMP = TEMP + 1
IF (INDEX(LINE, '(').EQ.0) GOTO 4
TEMP2 = INDEX(LINE, '(') + 1
LINE = LINE(TEMP2:)
TEMP2 = 5601
INIF = 1
GOTO 20001
5601 INIF = 0
IF (RETTYP.NE.4) WRITE (*,'(A)')'INVALID RETURN TYPE FOR ELSE IF'
WRITE (9, '(A)') 'POP R1'
WRITE (TMPSR2, *) TEMP
WRITE (TMPSTR, *) IFTBL(IFPTR)/1000
TMPSTR = TRIM(ADJUSTL(TMPSTR))//'_'//TRIM(ADJUSTL(TMPSR2))
WRITE(9,'(A)')'BRZ .IF_END_'//TRIM(TMPSTR)//' R1'
IFTBL(IFPTR) = IFTBL(IFPTR)/1000*1000 + TEMP
GOTO 1000
C END
5700 IF (IFPTR.EQ.0) THEN
WRITE (TMPSTR, *) LINEN
WRITE (*, '(A)') 'ON LINE: '//TRIM(ADJUSTL(TMPSTR))
WRITE (*, '(A)') 'UNEXPECTED ''END'' STATEMENT'
CLOSE(8)
CLOSE(9)
STOP
END IF
TEMP = IFTBL(IFPTR)
IF (TEMP.GE.2000000000) THEN
WRITE (TMPSTR, *) LINEN
WRITE (*, '(A)') 'ON LINE '//TRIM(ADJUSTL(TMPSTR))
WRITE (*,'(A)')'END STATEMENT BEFORE TERMINAL STATEMENT OF DO'
STOP
ELSE IF (TEMP.GE.1000000000) THEN
WRITE (TMPSTR, *) TEMP - 1000000000
LINE = EACHDO(VDOPTR)
TEMP2 = 7003
GOTO 20001
ELSE IF (TEMP.EQ.1000000) THEN
WRITE (9, '(A)') 'HLT'
ELSE IF (TEMP.EQ.2000000) THEN
WRITE (9, '(A)') 'RET'
ELSE
TEMP2 = TEMP/1000
TEMP = TEMP-TEMP2*1000
WRITE (TMPSTR, *) TEMP2
TMPSTR = ADJUSTL(TMPSTR)
WRITE (9, '(A)') '.IF_END_'//TRIM(TMPSTR)//'_REAL'
WRITE (TMPSR2, *) TEMP
TMPSR2 = ADJUSTL(TMPSR2)
WRITE (9, '(A)') '.IF_END_'//TRIM(TMPSTR)//'_'//TRIM(TMPSR2)
END IF
IFPTR = IFPTR - 1
GOTO 1000
C WRITE
6000 LINE = ADJUSTL(LINE(6:))
IF (LINE(1:1).NE.'(') GOTO 4
LINE = ADJUSTL(LINE(2:))
C TERMINAL OUTPUT ONLY FOR NOW
IF (LINE(1:1).NE.'*') GOTO 4
TEMP = INDEX(LINE,',') + 1
LINE = ADJUSTL(LINE(TEMP:))
C ONLY STRING FORMAT SUPPORTED FOR NOW (UNFORMATTED COMING LATER)
IF (LINE(:5).NE.'''(A)''') GOTO 6200
LINE = ADJUSTL(LINE(6:))
TEMP = 1
IF (LINE(:14).EQ.', ADVANCE=''NO''') THEN
TEMP = 0
LINE = ADJUSTL(LINE(15:))
END IF
IF (LINE(:1).NE.')') GOTO 4
LINE = LINE(2:)
6011 WRITE (9, '(A)') 'MOV R6 SP', 'PSH @MAX'
IF (LINE.EQ.'') GOTO 4
RETTYP = 0
6010 TEMP2 = 6010
IF (RETTYP.EQ.1) WRITE (9, '(A)') 'PSH 1'
IF (LINE.EQ.'') GOTO 6100
COMEXT = .TRUE.
GOTO 20001
6100 WRITE (9, '(A)') 'MOV R4 SP','//','LOD R1 R4'
IF (TEMP.EQ.1) THEN
WRITE (9, '(A)') 'BRE ~+16 R1 @MAX'
ELSE
WRITE (9, '(A)') 'BRE ~+15 R1 @MAX'
END IF
WRITE (9, '(A)') 'ADD R2 R1 R4','INC R2 R2','LOD R3 R2',
2'BRE ~+3 R3 @MAX','MOV R4 R2','JMP ~-7','STR R4 @MAX',
3'DEC R2 R2','LOD R3 R2','BRE ~+4 R3 @MAX','OUT %TEXT R3',
4'DEC R1 R1','BNZ ~-5 R1'
IF (TEMP.EQ.1) THEN
WRITE (9, '(A)') 'OUT %TEXT 10', 'JMP ~-17','MOV SP R6'
ELSE
WRITE (9, '(A)') 'JMP ~-16','MOV SP R6'
END IF
GOTO 1000
6200 IF (LINE(:1).NE.'*') GOTO 4
LINE = ADJUSTL(LINE(2:))
TEMP3 = 1
IF (LINE(:14).EQ.', ADVANCE=''NO''') THEN
TEMP3 = 0
LINE = ADJUSTL(LINE(15:))
END IF
IF (LINE(:1).NE.')') GOTO 4
LINE = LINE(2:)
IF (LINE.EQ.'') GOTO 4
TEMP = 0
6251 IF (LINE.EQ.'') GOTO 1000
WRITE (9, '(A)') 'MOV R6 SP','PSH @MAX'
TEMP2 = 6210
COMEXT = .TRUE.
GOTO 20001
6210 IF (RETTYP.EQ.1) THEN
WRITE(9, '(A)') '//', 'POP R1', 'IMM R2 12', 'MOV R5 R0'
WRITE(9, '(A)') 'BRP ~+3 R1', 'IMM R5 1', 'NEG R1 R1'
WRITE(9, '(A)') 'MOD R4 R1 10', 'ADD R4 R4 48', 'PSH R4'
WRITE(9, '(A)') 'DIV R1 R1 10', 'DEC R2 R2', 'BRZ ~+7 R1'
WRITE(9, '(A)') 'BNZ ~-6 R2', 'JMP ~+12', 'PSH 43'
WRITE(9, '(A)') 'DEC R2 R2', 'BNZ ~-2 R2', 'JMP ~+8'
WRITE(9, '(A)') 'BRZ ~+3 R5', 'PSH 45', 'DEC R2 R2'
WRITE(9, '(A)') 'BRZ ~+4 R2', 'PSH 32', 'DEC R2 R2'
WRITE(9, '(A)') 'BNZ ~-2 R2', 'POP R1', 'BRN ~+4 R1'
WRITE(9, '(A)') 'OUT %TEXT R1', 'JMP ~-3', 'INC SP SP'
TEMP = 1
ELSE IF (RETTYP.EQ.2) THEN
IF (TEMP.NE.2) WRITE (9, '(A)') 'OUT %TEXT 32'
WRITE (9, '(A)') 'MOV R4 SP','//','LOD R1 R4',
1'BRE ~+15 R1 @MAX','ADD R2 R1 R4','INC R2 R2','LOD R3 R2',
2'BRE ~+3 R3 @MAX','MOV R4 R2','JMP ~-7','STR R4 @MAX',
3'DEC R2 R2','LOD R3 R2','BRE ~+4 R3 @MAX','OUT %TEXT R3',
4'DEC R1 R1','BNZ ~-5 R1','JMP ~-16',
5'MOV SP R6'
TEMP = 2
END IF
IF (LINE.EQ.''.AND.TEMP3.NE.0) WRITE (9, '(A)') 'OUT %TEXT 10'
GOTO 6251
C DO STATEMENT
7000 LINE = ADJUSTL(LINE(4:))
IFPTR = IFPTR + 1
IF (LINE(:1).GE.'0'.AND.LINE(:1).LE.'9') THEN
TEMP = INDEX(LINE, ' ')-1
TMPSTR = LINE(:TEMP)
TEMP = TEMP + 2
LINE = ADJUSTL(LINE(TEMP:))
READ (TMPSTR, *) TEMP
IFTBL(IFPTR) = 2000000000 + TEMP
TMPSR4 = '.DO_TOP_RANGE_'//TRIM(TMPSTR)
ELSE
IFTBL(IFPTR) = 1000000000 + IFNUM
WRITE (TMPSTR, *) IFNUM
TMPSR4 = '.DO_TOP_'//TRIM(ADJUSTL(TMPSTR))
IFNUM = IFNUM + 1
END IF
TEMP = INDEX(LINE, '=')-1
TMPSR3 = LINE(:TEMP)
COMEXT = .TRUE.
TEMP3 = 1
GOTO 3002
7001 WRITE (9, '(A)') TRIM(TMPSR4)
VARDO(VDOPTR) = TRIM(VARDO(VDOPTR))//CHAR(10)//'JMP '//TMPSR4
TMPSR4(5:7) = 'END'
VARDO(VDOPTR) = TRIM(VARDO(VDOPTR))//CHAR(10)//TMPSR4
TEMP = INDEX(LINE, ',') + 1
IF (TEMP.NE.1) THEN
TMPSTR = LINE(TEMP:)
TEMP = TEMP - 2
LINE = LINE(:TEMP)
ELSE
TMPSTR = ''
END IF
LINE ='ABS('//TRIM(TMPSR3)//').LE.ABS('//TRIM(ADJUSTL(LINE))//')'
TMPSR3 = TMPSTR
TEMP2 = 7002
GOTO 20001
7002 LINE = ADJUSTL(TMPSR3)
IF (LINE(:1).EQ.' ') THEN
EACHDO(VDOPTR) = '1'
ELSE
EACHDO(VDOPTR) = LINE
END IF
7004 WRITE (9, '(A)') 'POP R1'
WRITE (9, '(A)') 'BRZ '//TRIM(TMPSR4)//' R1'
GOTO 1000
7003 WRITE (9, '(A)') 'POP R8'
WRITE (9, '(A)') TRIM(VARDO(VDOPTR))
VDOPTR = VDOPTR - 1
INIF = 0
IFPTR = IFPTR - 1
GOTO 1000
7100 TEMP = IFPTR
C EXIT STATEMENT
7101 TEMP2 = IFTBL(TEMP)
IF (TEMP2.GE.2000000000) THEN
WRITE (TMPSTR, *) TEMP2-2000000000
WRITE (9,'(A)') 'JMP .DO_END_RANGE_'//TRIM(ADJUSTL(TMPSTR))
ELSE IF (TEMP2.GE.1000000000) THEN
WRITE (TMPSTR, *) TEMP2-1000000000
WRITE (9,'(A)') 'JMP .DO_END_'//TRIM(ADJUSTL(TMPSTR))
ELSE
TEMP = TEMP - 1
IF (TEMP.EQ.0) GOTO 4
GOTO 7101
END IF
GOTO 1000
C SUBROUTINES
8000 LINE = ADJUSTL(LINE(11:))
TEMP = INDEX(LINE, '(') - 1
TMPSTR = LINE(:TEMP)
IF (TOP) WRITE (9, '(A)') 'JMP .__MAIN'
WRITE (9, '(A)') '', '.__SUB_'//TRIM(ADJUSTL(TMPSTR))
VARPTR = 1
VARS(VARPTR) = ''
IFPTR = IFPTR + 1
IFTBL(IFPTR) = 2000000
DECBLK = .TRUE.
TEMP = TEMP + 2
ARGPTR = 0
LINE = ADJUSTL(LINE(TEMP:))
8001 IF (LINE(:1).EQ.')'.OR.LINE(:1).EQ.' ') GOTO 8002
TEMP = INDEX(LINE, ',')-1
IF (TEMP.EQ.-1) TEMP = INDEX(LINE, ')') - 1
TMPSTR = LINE(:TEMP)
TEMP = TEMP + 2
LINE = ADJUSTL(LINE(TEMP:))
ARGPTR = ARGPTR + 1
ARGS(ARGPTR) = TMPSTR(:6)
GOTO 8001
8002 ARGPTR = ARGPTR + 1
ARGS(ARGPTR) = ''
GOTO 1000
8500 WRITE (9, '(A)') 'POP R2'
DO TEMP = ARGPTR-1, 1, -1
TMPSTR = ARGS(TEMP)
DO TEMP2 = 1, 64
TMPSR2 = VARS(TEMP2)
IF (TMPSR2.EQ.TMPSTR) THEN
IF (VARTYP(TEMP2)/2000.EQ.2) THEN
WRITE (TMPSR2, *) VARADR(TEMP2)
WRITE (TMPSTR, *) MOD(VARTYP(TEMP2),2000)
WRITE (TMPSR3, *) VARADR(TEMP2)-1
TMPSR2 = ADJUSTL(TMPSR2)
TMPSTR = ADJUSTL(TMPSTR)
TMPSR3 = ADJUSTL(TMPSR3)
WRITE (9,'(A)') 'POP R1','BNZ ~+4 R1','POP R1'
WRITE (9, '(A)') 'STR M'//TRIM(TMPSR2)//' R1','JMP ~+7','POP R1'
WRITE (9, '(A)') 'IMM R3 '//TRIM(TMPSTR),'POP R4'
WRITE (9, '(A)') 'LSTR M'//TRIM(TMPSR3)//' R3 R4','DEC R3 R3'
WRITE (9, '(A)') 'BNZ ~-3 R3'
ISPTR(TEMP2) = .TRUE.
EXIT
END IF
WRITE (9, '(A)') 'POP R1'
WRITE (TMPSTR, *) VARADR(TEMP2)
TMPSTR = ADJUSTL(TMPSTR)
ISPTR(TEMP2) = .TRUE.
WRITE (9, '(A)') 'STR M'//TRIM(TMPSTR)//' R1'
EXIT
END IF
END DO
IF (TEMP2.EQ.65) THEN
IF (.NOT.IMPLIC) GOTO 7
VARS(VARPTR) = TMPSTR(:6)
VARADR(VARPTR) = CRTVAR
WRITE (TMPSR2, *) CRTVAR
CRTVAR = CRTVAR + 1
ISPTR(VARPTR) = .TRUE.
IF (TMPSTR(:1).GT.'N'.OR.TMPSTR(:1).LT.'I') THEN
VARTYP(VARPTR) = 3000
ELSE
VARTYP(VARPTR) = 1000
END IF
VARSZE(VARPTR) = 4
VARPTR = VARPTR + 1
WRITE (9, '(A)') 'POP R1'
WRITE (9, '(A)')'STR M'//TRIM(ADJUSTL(TMPSR2))//' R1'
END IF
END DO
WRITE (9, '(A)') 'PSH R2'
ARGPTR = 0
DECBLK = .FALSE.
GOTO 8501
8600 LINE = ADJUSTL(LINE(5:))
TEMP = INDEX(LINE, '(') - 1
TMPSR3 = LINE(:TEMP)
TEMP = TEMP + 2
LINE = LINE(TEMP:)
TMPPTR = 0
8601 IF (LINE.EQ.'') GOTO 8602
TEMP = INDEX(LINE, ',')-1
IF (TEMP.EQ.-1) TEMP = INDEX(LINE, ')') - 1
TMPSTR = ADJUSTL(LINE(:TEMP))
DO TEMP2 = 1, 64
TMPSR2 = VARS(TEMP2)
IF (TMPSR2(:1).EQ.' ') EXIT
IF (TMPSR2.EQ.TMPSTR) THEN
WRITE (TMPSTR, *) VARADR(TEMP2)
TMPSTR = ADJUSTL(TMPSTR)
WRITE (9, '(A)') 'PSH M'//TRIM(TMPSTR)
TEMP = TEMP + 2
LINE = LINE(TEMP:)
GOTO 8601
END IF
END DO
COMEXT = .TRUE.
INIF = 1
TEMP2 = 8603
GOTO 20001
8603 WRITE (TMPSTR, *) CRTVAR
WRITE (9, '(A)') 'POP R1'
WRITE (9, '(A)') 'STR M'//TRIM(ADJUSTL(TMPSTR))//' R1'
WRITE (9, '(A)') 'PSH M'//TRIM(ADJUSTL(TMPSTR))
CRTVAR = CRTVAR + 1
GOTO 8601
8602 INIF = 0
WRITE (9, '(A)') 'CAL .__SUB_'//TRIM(ADJUSTL(TMPSR3))
GOTO 1000
C ERRORS
1 WRITE(TMPSTR, *) LINEN
WRITE (*, '(A)') 'I/O ERROR ON LINE ', TRIM(ADJUSTL(TMPSTR))
CLOSE (8)
CLOSE (9)
STOP
2 IF (IFPTR.NE.0) WRITE (*,'(A)') 'UNEXPECTED EOF'
CLOSE (8)
CLOSE (9)
STOP
3 WRITE (*,'(A)') 'CONTINUATION LINES UNSUPPORTED'
CLOSE (8)
CLOSE (9)
STOP
4 WRITE(TMPSTR, *) LINEN
WRITE (*,'(A)') 'SYNTAX ERROR ON LINE '//TRIM(ADJUSTL(TMPSTR))
CLOSE (8)
CLOSE (9)
STOP
5 WRITE (*, '(A)') 'UNDEFINED FUNCTION: '//FUNCS(TEMP)
CLOSE (7)
CLOSE (8)
CLOSE (9)
STOP
6 WRITE (TMPSR2, *) LINEN
WRITE (*, '(A)') 'ON LINE '//TRIM(ADJUSTL(TMPSR2))
WRITE (*, '(A)') 'INVALID SIZE FOR VARIABLE: '//TMPSTR
CLOSE (8)
CLOSE (9)
STOP
7 WRITE (TMPSR2, *) LINEN
WRITE (*, '(A)') 'ON LINE '//TRIM(ADJUSTL(TMPSR2))
WRITE (*, '(A)') 'VAR '''//TRIM(TMPSTR)//''' HAS NO TYPE'
CLOSE (8)
CLOSE (9)
STOP
C SHUNTING YARD
20001 OP = 1
SP = 0
DEPTH = 0
NALLOW = .TRUE.
20000 LINE = ADJUSTL(LINE)
IF (LINE(:1).EQ.' ') GOTO 28998
C OPERATORS
IF (LINE(:1).LT.'0') GOTO 30000
C VARS AND FUNCS
IF (LINE(:1).GT.'9') GOTO 40000
C NUMBER
TMPI = 72
IF (INDEX(LINE, ' ').NE.0) TMPI = INDEX(LINE, ' ')-1
IF (INDEX(LINE, '.').NE.0) TMPI = MIN(TMPI, INDEX(LINE, '.')-1)
IF (INDEX(LINE, ',').NE.0) TMPI = MIN(TMPI, INDEX(LINE, ',')-1)
IF (INDEX(LINE, '+').NE.0) TMPI = MIN(TMPI, INDEX(LINE, '+')-1)
IF (INDEX(LINE, '-').NE.0) TMPI = MIN(TMPI, INDEX(LINE, '-')-1)
IF (INDEX(LINE, '*').NE.0) TMPI = MIN(TMPI, INDEX(LINE, '*')-1)
IF (INDEX(LINE, '/').NE.0) TMPI = MIN(TMPI, INDEX(LINE, '/')-1)
IF (INDEX(LINE, ')').NE.0) TMPI = MIN(TMPI, INDEX(LINE, ')')-1)
IF (INDEX(LINE, ':').NE.0) TMPI = MIN(TMPI, INDEX(LINE, ':')-1)
TMPSTR = LINE(:TMPI)
TMPI = TMPI + 1
LINE = LINE(TMPI:)
READ (TMPSTR, *) TMPI
C PUSH INTEGER VALUE
OUT(OP) = 1
OP = OP + 1
OUT(OP) = TMPI
OP = OP + 1
NALLOW = .FALSE.
GOTO 20000
C HANDLE OPERATORS
C DEAL WITH LOGICAL RELATED THINGS
30000 IF (LINE(:1).EQ.'.') GOTO 35000
IF (LINE(:1).EQ.',') THEN
LINE = LINE(2:)
IF (DEPTH.EQ.0.AND.COMEXT) THEN
COMEXT = .FALSE.
GOTO 28998
END IF
GOTO 20000
END IF
C PARSE STRINGS
IF (LINE(:1).EQ.'''') GOTO 36000
IF (LINE(:1).EQ.'(') THEN
DEPTH = DEPTH + 1
SP = SP + 1
STACK(SP) = 6
LINE = LINE(2:)
NALLOW = .TRUE.
GOTO 20000
END IF
IF (LINE(:1).EQ.')') THEN
LINE = LINE(2:)
DEPTH = DEPTH - 1
30010 IF (SP.EQ.0) GOTO 11003
IF (STACK(SP).EQ.6) THEN
SP = SP - 1
IF (STACK(SP)/100.EQ.1) THEN
OUT(OP) = STACK(SP)
SP = SP - 1
OP = OP + 1
END IF
GOTO 20000
ELSE
OUT(OP) = STACK(SP)
OP = OP + 1
SP = SP - 1
GOTO 30010
END IF
END IF
IF (LINE(:1).EQ.'-'.AND.NALLOW) THEN
OUT(OP) = 1
OP = OP + 1
OUT(OP) = 0
OP = OP + 1
END IF
NALLOW = .FALSE.
IF (LINE(:2).EQ.'**') THEN
SP = SP + 1
STACK(SP) = 9
LINE = LINE(3:)
GOTO 20000
END IF
IF (LINE(:2).EQ.'//') THEN
30300 IF (SP.EQ.0) THEN
SP = SP + 1
STACK(SP) = 30
ELSE
TMPI = STACK(SP)
SP = SP - 1
IF (TMPI.LE.39.AND.TMPI.NE.6) THEN
OUT(OP) = TMPI
OP = OP + 1
GOTO 30300
END IF
SP = SP + 2
STACK(SP) = 30
END IF
LINE = LINE(3:)
GOTO 20000
END IF
IF (LINE(:1).EQ.'*') THEN
30100 IF (SP.EQ.0) THEN
SP = SP + 1
STACK(SP) = 10
ELSE
TMPI = STACK(SP)
SP = SP - 1
IF (TMPI.LE.19.AND.TMPI.NE.6) THEN
OUT(OP) = TMPI
OP = OP + 1
GOTO 30100
END IF
SP = SP + 2
STACK(SP) = 10
END IF
LINE = LINE(2:)
GOTO 20000
END IF
IF (LINE(:1).EQ.'/') THEN
30110 IF (SP.EQ.0) THEN
SP = SP + 1
STACK(SP) = 11
ELSE
TMPI = STACK(SP)
SP = SP - 1
IF (TMPI.LE.19.AND.TMPI.NE.6) THEN
OUT(OP) = TMPI
OP = OP + 1
GOTO 30110
END IF
SP = SP + 2
STACK(SP) = 11
END IF
LINE = LINE(2:)
GOTO 20000
END IF
IF (LINE(:1).EQ.'+') THEN
30200 IF (SP.EQ.0) THEN
SP = SP + 1
STACK(SP) = 20
ELSE
TMPI = STACK(SP)
SP = SP - 1
IF (TMPI.LE.29.AND.TMPI.NE.6) THEN
OUT(OP) = TMPI
OP = OP + 1
GOTO 30200
END IF
SP = SP + 2
STACK(SP) = 20
END IF
LINE = LINE(2:)
GOTO 20000
END IF
IF (LINE(:1).EQ.'-') THEN
30210 IF (SP.EQ.0) THEN
SP = SP + 1
STACK(SP) = 21
ELSE
TMPI = STACK(SP)
SP = SP - 1
IF (TMPI.LE.29.AND.TMPI.NE.6) THEN
OUT(OP) = TMPI
OP = OP + 1
GOTO 30210
END IF
SP = SP + 2