-- file: TangleScan.mesa
-- Pascal-to-Mesa translator output, translated at September 14, 1985 3:58:20 pm PDT


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  TanglePrivate,
  TangleProcArray;

TangleScan: PROGRAM IMPORTS PascalWizardFiles, TanglePrivate, TangleProcArray EXPORTS TanglePrivate = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, TanglePrivate, TangleProcArray;
--:145----157:-- ScanNumeric: PROCEDURE[P: NamePointer] = 
BEGIN 
 Accumulator:PascalInteger;NextSign:PascalInteger[-1..1];Q:NamePointer;Val:PascalInteger;
--158:--
 Accumulator←0;NextSign←1;
{WHILE TRUE DO BEGIN NextControl←GetNext[];
DO {--Label21:--SELECT NextControl FROM 48,49,50,51,52,53,54,55,56,57 =>BEGIN--160:--Val←0;
DO Val←10*Val+NextControl-48;NextControl←GetNext[];
 IF( INT[NextControl]>57)OR ( INT[NextControl]<48)--:160-- THEN EXIT; ENDLOOP;
BEGIN Accumulator←Accumulator+NextSign*(Val);NextSign←1; END;
 GOTO Label21; END;12 =>BEGIN--161:--Val←0;NextControl←48;
DO Val←8*Val+NextControl-48;NextControl←GetNext[];
 IF( INT[NextControl]>55)OR ( INT[NextControl]<48)--:161-- THEN EXIT; ENDLOOP;
BEGIN Accumulator←Accumulator+NextSign*(Val);NextSign←1; END;
 GOTO Label21; END;13 =>BEGIN--162:--Val←0;NextControl←48;
DO IF  INT[NextControl]>=65  THEN NextControl←NextControl-7;
Val←16*Val+NextControl-48;NextControl←GetNext[];
 IF( INT[NextControl]>70)OR ( INT[NextControl]<48)OR (( INT[NextControl]>57)AND (
 INT[NextControl]<65))--:162-- THEN EXIT; ENDLOOP;BEGIN Accumulator←Accumulator+NextSign*(Val);
NextSign←1; END; GOTO Label21; END;130 =>BEGIN Q←IdLookup[0];
IF Ilk↑[Q]#1  THEN BEGIN NextControl←42; GOTO Label21; END;
BEGIN Accumulator←Accumulator+NextSign*( INT[Equiv↑[Q]]-32768);NextSign←1;
 END; END;43 => NULL;45 =>NextSign←-NextSign;132,133,135,134,136 => GOTO Label30;
59 =>BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! Omit semicolon in numeric definition"];Error[]; END;
 ENDCASE =>--159:--BEGIN BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! Improper numeric definition will be flushed"];Error[];
 END;DO NextControl←SkipAhead []; IF( INT[NextControl]>=132) THEN EXIT; ENDLOOP;
IF NextControl=135  THEN BEGIN Loc←Loc-2;NextControl←GetNext[]; END;
Accumulator←0; GOTO Label30; END--:159--;EXIT; EXITS Label21 => NULL} ENDLOOP; END ENDLOOP ;EXITS Label30 => NULL};--:158--IF ABS[Accumulator]>=32768  THEN BEGIN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Value too big: "]; PascalWriteInteger[file: @TermOut, item: Accumulator, fieldMinLength: 1]};Error[]; END;
Accumulator←0; END;Equiv↑[P]←Accumulator+32768; END;--:157----165:
 ScanRepl: PROCEDURE[T: EightBits] = 
BEGIN  A:SixteenBits;
B:AsciiCode;Bal:EightBits; Bal←0;
{WHILE TRUE DO BEGIN DO {--Label22:--A←GetNext[];SELECT A FROM 40 =>Bal←Bal+1;
41 =>IF Bal=0  THEN BEGIN PascalWriteLn[file: @TermOut];PascalWriteLongString[file: @TermOut, item: "! Extra )"];
Error[]; END  ELSE Bal←Bal-1;39 =>--168:--BEGIN B←39;
{WHILE TRUE DO BEGIN BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN 
PascalWriteLn[file: @TermOut];{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};
Error[];History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←B;
TokPtr↑[Z]←TokPtr↑[Z]+1; END;
IF B=64  THEN IF Buffer↑[Loc]=64  THEN Loc←Loc+1  ELSE BEGIN 
PascalWriteLn[file: @TermOut];PascalWriteLongString[file: @TermOut, item: "! You should double @ signs in strings"];
Error[]; END;IF Loc=Limit  THEN BEGIN BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! String didn't end"];Error[]; END;Buffer↑[Loc]←39;
Buffer↑[Loc+1]←0; END;B←Buffer↑[Loc];Loc←Loc+1;
IF B=39  THEN BEGIN IF Buffer↑[Loc]#39  THEN  GOTO Label31  ELSE BEGIN Loc←Loc+1
;BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←39;
TokPtr↑[Z]←TokPtr↑[Z]+1; END; END; END; END ENDLOOP ;EXITS Label31 => NULL}; END--:168--;
35 =>IF T=3  THEN A←0;--167:--130 =>BEGIN A←IdLookup[0];
BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑← INT[( A /256)]+128;
TokPtr↑[Z]←TokPtr↑[Z]+1; END;A← A MOD 256; END;
135 =>IF T#135  THEN  GOTO Label30  ELSE BEGIN BEGIN IF TokPtr↑[Z]=MaxToks  THEN
BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←( CurModule /256)+168;
TokPtr↑[Z]←TokPtr↑[Z]+1; END;A← CurModule MOD 256; END;2 =>--169:
BEGIN BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←2;
TokPtr↑[Z]←TokPtr↑[Z]+1; END;Buffer↑[Limit+1]←64;
WHILE Buffer↑[Loc]#64 DO BEGIN BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN
PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←Buffer↑[Loc];
TokPtr↑[Z]←TokPtr↑[Z]+1; END;Loc←Loc+1;
IF  INT[Loc]<Limit  THEN IF(Buffer↑[Loc]=64)AND (Buffer↑[Loc+1]=64) THEN BEGIN
BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←64;
TokPtr↑[Z]←TokPtr↑[Z]+1; END;Loc←Loc+2; END; END ENDLOOP ;
IF  INT[Loc]>=Limit  THEN BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! Verbatim string didn't end"];Error[];
 END  ELSE IF Buffer↑[Loc+1]#62  THEN BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! You should double @ signs in verbatim strings"];Error[];
 END;Loc←Loc+2; END--:169--;
133,132,134 =>IF T#135  THEN  GOTO Label30  ELSE BEGIN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! @"]; PascalWriteChar[file: @TermOut, item: Xchr↑[Buffer↑[Loc-1]]]; PascalWriteLongString[file: @TermOut, item: " is ignored in Pascal text"]};
Error[]; END; GOTO Label22; END;136 => GOTO Label30;--:167-- ENDCASE => NULL;
BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←A;
TokPtr↑[Z]←TokPtr↑[Z]+1; END;EXIT; EXITS Label22 => NULL} ENDLOOP; END ENDLOOP ;EXITS Label30 => NULL};NextControl←A;--166:
IF  INT[Bal]>0  THEN BEGIN IF Bal=1  THEN BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! Missing )"];Error[]; END  ELSE BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Missing "]; PascalWriteInteger[file: @TermOut, item: Bal, fieldMinLength: 1]; PascalWriteLongString[file: @TermOut, item: " )'s"]};Error[]; END;
WHILE  INT[Bal]>0 DO BEGIN BEGIN IF TokPtr↑[Z]=MaxToks  THEN BEGIN 
PascalWriteLn[file: @TermOut];{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "token"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};
Error[];History←3;JumpOut[]; END;TokMem[Z, TokPtr↑[Z]]↑←41;
TokPtr↑[Z]←TokPtr↑[Z]+1; END;Bal←Bal-1; END ENDLOOP ; END--:166--;
IF  INT[TextPtr]>MaxTexts-3  THEN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Sorry, "]; PascalWriteLongString[file: @TermOut, item: "text"]; PascalWriteLongString[file: @TermOut, item: " capacity exceeded"]};Error[];
History←3;JumpOut[]; END;CurReplText←TextPtr;
TokStart↑[TextPtr+3]←TokPtr↑[Z];TextPtr←TextPtr+1;
IF Z=2  THEN Z←0  ELSE Z←Z+1; END;--:165----170:
 DefineMacro: PROCEDURE[T: EightBits] = 
BEGIN P:NamePointer;
 P←IdLookup[T];ScanRepl[T];Equiv↑[P]←CurReplText;
TextLink↑[CurReplText]←0; END;--:170----172:-- ScanModule: PROCEDURE
 = 
BEGIN  P:NamePointer; --175:--  --:175--  ModuleCount←ModuleCount+1;
--173:--NextControl←0;
{WHILE TRUE DO BEGIN  DO {--Label22:--WHILE  INT[NextControl]<=132 DO BEGIN NextControl←
SkipAhead[];IF NextControl=135  THEN BEGIN Loc←Loc-2;
NextControl←GetNext[]; END; END ENDLOOP ;IF NextControl#133  THEN  GOTO Label30;
NextControl←GetNext[];
IF NextControl#130  THEN BEGIN BEGIN PascalWriteLn[file: @TermOut];
{PascalWriteLongString[file: @TermOut, item: "! Definition flushed, must start with "]
; PascalWriteLongString[file: @TermOut, item: "identifier of length > 1"]};Error[]; END; GOTO Label22; END;
NextControl←GetNext[];
IF NextControl=61  THEN BEGIN ScanNumeric[IdLookup[1]]; GOTO Label22;
 END  ELSE IF NextControl=30  THEN BEGIN DefineMacro[2]; GOTO Label22;
 END  ELSE--174:--IF NextControl=40  THEN BEGIN NextControl←GetNext[];
IF NextControl=35  THEN BEGIN NextControl←GetNext[];
IF NextControl=41  THEN BEGIN NextControl←GetNext[];
IF NextControl=61  THEN BEGIN BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! Use == for macros"];Error[]; END;NextControl←30; END;
IF NextControl=30  THEN BEGIN DefineMacro[3]; GOTO Label22; END; END; END; END;
--:174--BEGIN PascalWriteLn[file: @TermOut];
PascalWriteLongString[file: @TermOut, item: "! Definition flushed since it starts badly"];Error[]; END;
EXIT; EXITS Label22 => NULL} ENDLOOP; END ENDLOOP ;EXITS Label30 => NULL};--:173--{SELECT NextControl FROM 134 =>P←0;
135 =>BEGIN P←CurModule;--176:--DO NextControl←GetNext[];
 IF NextControl#43 THEN EXIT; ENDLOOP;
IF(NextControl#61)AND (NextControl#30) THEN BEGIN BEGIN 
PascalWriteLn[file: @TermOut];PascalWriteLongString[file: @TermOut, item: "! Pascal text flushed, = sign is missing"];
Error[]; END;DO NextControl←SkipAhead[]; IF NextControl=136 THEN EXIT; ENDLOOP;
 GOTO Label10; END--:176--; END; ENDCASE => GOTO Label10 ;--177:
StoreTwoBytes[53248+ModuleCount];--:177--ScanRepl[135];--178:
IF P=0  THEN BEGIN TextLink↑[LastUnnamed]←CurReplText;
LastUnnamed←CurReplText;
 END  ELSE IF Equiv↑[P]=0  THEN Equiv↑[P]←CurReplText  ELSE BEGIN P←Equiv↑
[P];WHILE  INT[TextLink↑[P]]<MaxTexts DO P←TextLink↑[P] ENDLOOP ;
TextLink↑[P]←CurReplText; END;TextLink↑[CurReplText]←MaxTexts;
--:178--EXITS Label10 => NULL}; END;--:172----181:----PROCEDURE DEBUG←HELP;LABEL 888,10;
-- VAR K:INTEGER;BEGIN DEBUG←SKIPPED:=DEBUG←SKIPPED+1;
-- IF DEBUG←SKIPPED<DEBUG←CYCLE THEN GOTO 10;DEBUG←SKIPPED:=0;
-- WHILE TRUE DO BEGIN WRITE(TERM←OUT,'#');BREAK(TERM←OUT);
-- READ(TERM←IN,DDT);
-- IF DDT<0 THEN GOTO 10 ELSE IF DDT=0 THEN BEGIN GOTO 888;
-- 888:DDT:=0;
-- END ELSE BEGIN READ(TERM←IN,DD);CASE DDT OF 1:PRINT←ID(DD);
-- 2:PRINT←REPL(DD);3:FOR K:=1 TO DD DO WRITE(TERM←OUT,XCHR[BUFFER[K]]);
-- 4:FOR K:=1 TO DD DO WRITE(TERM←OUT,XCHR[MOD←TEXT[K]]);
-- 5:FOR K:=1 TO OUT←PTR DO WRITE(TERM←OUT,XCHR[OUT←BUF[K]]);
-- 6:FOR K:=1 TO DD DO WRITE(TERM←OUT,XCHR[OUT←CONTRIB[K]]);
-- OTHERS:WRITE(TERM←OUT,'?')END;END;END;10:END;----:181----182:

END.