-- file: MFInputImpl1.mesa
-- Pascal-to-Mesa translator output, translated at October 31, 1985 4:28:02 pm PST


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  MFTypes,
  MFProcArray,
  MFExternals,
  MFInteraction,
  MFMath,
  MFMemory,
  MFSymbols,
  MFInput,
  MFParsing;

MFInputImpl1: PROGRAM IMPORTS PascalBasic, PascalWizardFiles, MFProcArray, MFExternals, MFInteraction, MFMath, MFMemory, MFSymbols, MFParsing EXPORTS MFInput = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, MFTypes, MFProcArray, MFExternals, MFInteraction, MFMath, MFMemory, MFSymbols, MFInput, MFParsing;
--:591----623:--
CurCmd: EightBits;


CurMod: PascalInteger;

CurSym: Halfword;
--:623----627:
InputStack: LONG POINTER TO ARRAY PascalInteger[0..30] OF InStateRecord ← PascalStaticZone.NEW[ARRAY PascalInteger[0..30] OF InStateRecord];


InputPtr: PascalInteger[0..StackSize];

MaxInStack: PascalInteger[0..StackSize];


CurInput: InStateRecord;
--:627----630:--
InOpen: PascalInteger[0..6];

InputFile: LONG POINTER TO ARRAY PascalInteger[1..6] OF AlphaFile ← PascalStaticZone.NEW[ARRAY PascalInteger[1..6] OF AlphaFile];

Line: PascalInteger;

LineStack: LONG POINTER TO ARRAY PascalInteger[1..6] OF PascalInteger ← PascalStaticZone.NEW[ARRAY PascalInteger[1..6] OF PascalInteger];
--:630----632:
ParamStack: LONG POINTER TO ARRAY PascalInteger[0..150] OF Halfword ← PascalStaticZone.NEW[ARRAY PascalInteger[0..150] OF Halfword];

ParamPtr: PascalInteger[0..150];


MaxParamStack: PascalInteger;
--:632----633:--
FilePtr: PascalInteger[0..StackSize];
--:633----658:

ScannerStatus: PascalInteger[0..6];

WarningInfo: PascalInteger;
--:658----679:--
ForceEof: PascalBoolean;
--:698----737:--
CondPtr: Halfword;


IfLimit: PascalInteger[0..4];

CurIf: SmallNumber;

IfLine: PascalInteger;
--:737----751:

LoopPtr: Halfword;
--:27----30:
 InputLn: PROCEDURE[ F: LONG POINTER TO AlphaFile,BypassEoln: PascalBoolean] RETURNS[InputLnResult: PascalBoolean]
 = 
BEGIN LastNonblank:PascalInteger[0..BufSize];
 IF BypassEoln  THEN IF  NOT PascalTextEOF[file: @F↑] THEN PascalTextGET[file: @F↑];Last←First;
IF PascalTextEOF[file: @F↑] THEN InputLnResult←FALSE  ELSE BEGIN LastNonblank←First;
WHILE  NOT PascalTextEOLN[file: @F↑]DO BEGIN IF  INT[Last]>=MaxBufStack  THEN BEGIN
MaxBufStack←Last+1;
IF MaxBufStack=BufSize  THEN Overflow[128,BufSize]; END;
Buffer↑[Last]←Xord↑[PascalTextElement[file: @F↑]];PascalTextGET[file: @F↑];Last←Last+1;
IF Buffer↑[Last-1]#32  THEN LastNonblank←Last; END ENDLOOP ;Last←LastNonblank;
InputLnResult←TRUE; END; END;--:30----36:-- BeginTokenList: PROCEDURE[P: Halfword,T: Quarterword]
 = 
BEGIN BEGIN IF  INT[InputPtr]>MaxInStack  THEN BEGIN MaxInStack←InputPtr
;IF InputPtr=StackSize  THEN Overflow[481,StackSize]; END;
InputStack↑[InputPtr]←CurInput;InputPtr←InputPtr+1; END;
CurInput.StartField←P;CurInput.IndexField←T;
CurInput.LimitField←ParamPtr;CurInput.LocField←P; END;--:648----649:
 EndTokenList: PROCEDURE = 
BEGIN  P:Halfword;
 {IF  INT[CurInput.IndexField]>=10  THEN IF  INT[CurInput.IndexField]<=11
 THEN BEGIN FlushTokenList[CurInput.StartField]; GOTO Label30;
 END  ELSE DeleteMacRef[CurInput.StartField];
WHILE  INT[ParamPtr]>CurInput.LimitField DO BEGIN ParamPtr←ParamPtr-1;
P←ParamStack↑[ParamPtr];
IF P#0  THEN IF Mem[P]↑.Hh.Rh=1  THEN BEGIN RecycleValue[P];
FreeNode[P,2]; END  ELSE FlushTokenList[P]; END ENDLOOP ;
EXITS Label30 => NULL};BEGIN InputPtr←InputPtr-1;CurInput←InputStack↑[InputPtr]; END;
BEGIN IF Interrupt#0  THEN PauseForInstructions[]; END; END;--:649----650:
 CurTok: PROCEDURE RETURNS[CurTokResult: Halfword]
 = 
BEGIN P:Halfword;SaveType:SmallNumber;SaveExp:PascalInteger;
 IF CurSym=0  THEN IF CurCmd=38  THEN BEGIN SaveType←CurType;
SaveExp←CurExp;MakeExpCopy[CurMod];P←StashCurExp[];
Mem[P]↑.Hh.Rh←0;CurType←SaveType;CurExp←SaveExp;
 END  ELSE BEGIN P←GetNode[2];Mem[ INT[P]+1]↑.Int←CurMod;Mem[P]↑.Hh.B1←12;
IF CurCmd=42  THEN Mem[P]↑.Hh.B0←16  ELSE Mem[P]↑.Hh.B0←4;
 END  ELSE BEGIN BEGIN P←Avail;
IF P=0  THEN P←GetAvail [] ELSE BEGIN Avail←Mem[P]↑.Hh.Rh;Mem[P]↑.Hh.Rh←0;
DynUsed←DynUsed+1; END; END;Mem[P]↑.Hh.Lh←CurSym; END;CurTokResult←P; END;
--:650----651:-- BackInput: PROCEDURE = 
BEGIN P:Halfword; P←CurTok[];
WHILE( INT[CurInput.IndexField]>6)AND (CurInput.LocField=0)DO
EndTokenList[] ENDLOOP ;BeginTokenList[P,10]; END;--:651----652:
  BackError: PROCEDURE = 
BEGIN OkToInterrupt←FALSE;BackInput[];
OkToInterrupt←TRUE;Error[]; END; InsError: PROCEDURE
 = 
BEGIN OkToInterrupt←FALSE;BackInput[];CurInput.IndexField←11;
OkToInterrupt←TRUE;Error[]; END;--:652----653:
  BeginFileReading: PROCEDURE = 
BEGIN IF InOpen=6  THEN Overflow[482,6];
IF First=BufSize  THEN Overflow[128,BufSize];InOpen←InOpen+1;
BEGIN IF  INT[InputPtr]>MaxInStack  THEN BEGIN MaxInStack←InputPtr;
IF InputPtr=StackSize  THEN Overflow[481,StackSize]; END;
InputStack↑[InputPtr]←CurInput;InputPtr←InputPtr+1; END;
CurInput.IndexField←InOpen;LineStack↑[CurInput.IndexField]←Line;
CurInput.StartField←First;CurInput.NameField←0; END;--:653----654:
 EndFileReading: PROCEDURE = 
BEGIN First←CurInput.StartField;
Line←LineStack↑[CurInput.IndexField];
IF CurInput.IndexField#InOpen  THEN Confusion[483];
IF  INT[CurInput.NameField]>2  THEN AClose[@InputFile↑[CurInput.IndexField]
];BEGIN InputPtr←InputPtr-1;CurInput←InputStack↑[InputPtr]; END;
InOpen←InOpen-1; END;--:654----655:-- 
 ClearForErrorPrompt: PROCEDURE = 
BEGIN  WHILE( INT[CurInput.IndexField]<=6)AND (CurInput.NameField=0)AND (
 INT[InputPtr]>0)AND (CurInput.LocField=CurInput.LimitField)DO
EndFileReading[] ENDLOOP ;PrintLn[]; END;--:655----660:
 CheckOuterValidity: PROCEDURE RETURNS[CheckOuterValidityResult: PascalBoolean] = 
BEGIN P:Halfword;
 IF ScannerStatus=0  THEN CheckOuterValidityResult←TRUE  ELSE BEGIN
DeletionsAllowed←FALSE;--661:--IF CurSym#0  THEN BEGIN P←GetAvail[];
Mem[P]↑.Hh.Lh←CurSym;BeginTokenList[P,10]; END--:661--;
IF  INT[ScannerStatus]>1  THEN--662:--BEGIN Runaway[];
IF CurSym=0  THEN BEGIN IF Interaction=3  THEN NULL;PrintNl[133];Print[489];
 END  ELSE BEGIN BEGIN IF Interaction=3  THEN NULL;PrintNl[133];Print[490]; END;
 END;Print[491];BEGIN HelpPtr←4;HelpLine↑[3]←492;HelpLine↑[2]←493;
HelpLine↑[1]←494;HelpLine↑[0]←495; END;SELECT ScannerStatus FROM--663:
2 =>BEGIN Print[496];HelpLine↑[3]←497;CurSym←2235; END;
3 =>BEGIN Print[498];HelpLine↑[3]←499;
IF WarningInfo=0  THEN CurSym←2239  ELSE BEGIN CurSym←2231;
Eqtb↑[2231].Rh←WarningInfo; END; END;4,5 =>BEGIN Print[500];
IF ScannerStatus=5  THEN Print[Hash↑[WarningInfo].Rh] ELSE
PrintVariableName[WarningInfo];CurSym←2237; END;6 =>BEGIN Print[501];
Print[Hash↑[WarningInfo].Rh];Print[502];HelpLine↑[3]←503;CurSym←2236;
 END;--:663-- ENDCASE;InsError[]; END--:662-- ELSE BEGIN BEGIN IF Interaction=3  THEN NULL;
PrintNl[133];Print[484]; END;PrintInt[WarningInfo];BEGIN HelpPtr←3;
HelpLine↑[2]←485;HelpLine↑[1]←486;HelpLine↑[0]←487; END;
IF CurSym=0  THEN HelpLine↑[2]←488;CurSym←2238;InsError[]; END;
DeletionsAllowed←TRUE;CheckOuterValidityResult←FALSE; END; END;--:660----665:
--:665----666:-- 

 GetNext: PROCEDURE = 
BEGIN  K:PascalInteger[0..BufSize];KPlusOne:Halfword;
C:AsciiCode;Class:AsciiCode;N, F:PascalInteger; DO {--Label20:--CurSym←0;
{IF( INT[CurInput.IndexField]<=6) THEN--668:
BEGIN DO {--Label25:--C←Buffer↑[CurInput.LocField];
CurInput.LocField← INT[CurInput.LocField]+1;Class←CharClass↑[C];
{{{{SELECT Class FROM 0 => GOTO Label85;
1 =>BEGIN Class←CharClass↑[Buffer↑[CurInput.LocField]];
IF  INT[Class]>1  THEN  GOTO Label25  ELSE IF  INT[Class]<1  THEN BEGIN N←0; GOTO Label86; END; END;
2 => GOTO Label25;3 =>BEGIN--678:--IF  INT[CurInput.NameField]>2  THEN--680:
BEGIN Line←FileGetPos[@InputFile↑[CurInput.IndexField]];
First←CurInput.StartField;
IF  NOT ForceEof  THEN BEGIN IF InputLn[@InputFile↑[CurInput.IndexField
],TRUE] THEN FirmUpTheLine [] ELSE ForceEof←TRUE; END;
IF ForceEof  THEN BEGIN PrintChar[41];ForceEof←FALSE;PascalTextBREAK[file: @TermOut];
EndFileReading[];IF CheckOuterValidity [] THEN  GOTO Label20  ELSE  GOTO Label20; END;
Buffer↑[CurInput.LimitField]←37;First← INT[CurInput.LimitField]+1;
CurInput.LocField←CurInput.StartField; END--:680
 ELSE BEGIN IF  INT[InputPtr]>0  THEN BEGIN EndFileReading[]; GOTO Label20; END;
IF  INT[Selector]<2  THEN OpenLogFile[];
IF  INT[Interaction]>1  THEN BEGIN IF CurInput.LimitField=CurInput.
StartField  THEN PrintNl[518];PrintLn[];First←CurInput.StartField;
BEGIN Print[42];TermInput[]; END;CurInput.LimitField←Last;
Buffer↑[CurInput.LimitField]←37;First← INT[CurInput.LimitField]+1;
CurInput.LocField←CurInput.StartField; END  ELSE FatalError[519];
 END--:678--;BEGIN IF Interrupt#0  THEN PauseForInstructions[]; END; GOTO Label25;
 END;4 =>--670:
BEGIN IF Buffer↑[CurInput.LocField]=34  THEN CurMod←157  ELSE BEGIN K←
CurInput.LocField;Buffer↑[ INT[CurInput.LimitField]+1]←34;
DO CurInput.LocField← INT[CurInput.LocField]+1;
 IF Buffer↑[CurInput.LocField]=34 THEN EXIT; ENDLOOP;
IF  INT[CurInput.LocField]>CurInput.LimitField  THEN--671:
BEGIN CurInput.LocField←CurInput.LimitField;
BEGIN IF Interaction=3  THEN NULL;PrintNl[133];Print[511]; END;
BEGIN HelpPtr←3;HelpLine↑[2]←512;HelpLine↑[1]←513;HelpLine↑[0]←514;
 END;DeletionsAllowed←FALSE;Error[];DeletionsAllowed←TRUE; GOTO Label20;
 END--:671--;KPlusOne←K+1;
IF CurInput.LocField=KPlusOne  THEN CurMod←Buffer↑[K] ELSE BEGIN
BEGIN IF  INT[PoolPtr]+CurInput.LocField-K>MaxPoolPtr  THEN BEGIN IF
 INT[PoolPtr]+CurInput.LocField-K>PoolSize  THEN Overflow[129,
PoolSize-InitPoolPtr];MaxPoolPtr← INT[PoolPtr]+CurInput.LocField-K; END; END;
DO BEGIN StrPool↑[PoolPtr]←Buffer↑[K];PoolPtr←PoolPtr+1; END;
K←K+1; IF K=CurInput.LocField THEN EXIT; ENDLOOP;CurMod←MakeString[]; END; END;
CurInput.LocField← INT[CurInput.LocField]+1;CurCmd←39; GOTO Label10; END--:670
;5,6,7,8 =>BEGIN K← INT[CurInput.LocField]-1; GOTO Label40; END;20 =>--669:
BEGIN BEGIN IF Interaction=3  THEN NULL;PrintNl[133];Print[508]; END;
BEGIN HelpPtr←2;HelpLine↑[1]←509;HelpLine↑[0]←510; END;
DeletionsAllowed←FALSE;Error[];DeletionsAllowed←TRUE; GOTO Label20; END--:669
; ENDCASE => NULL;K← INT[CurInput.LocField]-1;
WHILE CharClass↑[Buffer↑[CurInput.LocField]]=Class DO CurInput.
LocField← INT[CurInput.LocField]+1 ENDLOOP ; GOTO Label40;EXITS Label85 => NULL};--672:--N←C-48;
WHILE CharClass↑[Buffer↑[CurInput.LocField]]=0 DO BEGIN IF N<4096  THEN
N←10*N+Buffer↑[CurInput.LocField]-48;
CurInput.LocField← INT[CurInput.LocField]+1; END ENDLOOP ;
{IF Buffer↑[CurInput.LocField]=46  THEN IF CharClass↑[Buffer↑[ INT[CurInput.
LocField]+1]]=0  THEN  GOTO Label30;F←0; GOTO Label87;
EXITS Label30 => NULL};CurInput.LocField← INT[CurInput.LocField]+1--:672--;EXITS Label86 => NULL};--673:--K←0;
DO IF  INT[K]<17  THEN BEGIN Dig↑[K]←Buffer↑[CurInput.LocField]-48;K←K+1;
 END;CurInput.LocField← INT[CurInput.LocField]+1;
 IF CharClass↑[Buffer↑[CurInput.LocField]]#0 THEN EXIT; ENDLOOP;F←RoundDecimals[K];
IF F=65536  THEN BEGIN N←N+1;F←0; END--:673--;EXITS Label87 => NULL};--674:
IF N<4096  THEN CurMod←N*65536+F  ELSE BEGIN BEGIN IF Interaction=3  THEN
 NULL;PrintNl[133];Print[515]; END;BEGIN HelpPtr←2;HelpLine↑[1]←516;
HelpLine↑[0]←517; END;DeletionsAllowed←FALSE;Error[];
DeletionsAllowed←TRUE;CurMod←268435455; END;CurCmd←42; GOTO Label10--:674
;EXITS Label40 => NULL};CurSym←IdLookup[K, INT[CurInput.LocField]-K];EXIT; EXITS Label25 => NULL} ENDLOOP; END--:668-- ELSE--675:
IF  INT[CurInput.LocField]>=HiMemMin  THEN BEGIN CurSym←Mem[CurInput.
LocField]↑.Hh.Lh;CurInput.LocField←Mem[CurInput.LocField]↑.Hh.Rh;
IF  INT[CurSym]>=2242  THEN IF  INT[CurSym]>=2392  THEN--676:
BEGIN IF  INT[CurSym]>=2542  THEN CurSym← INT[CurSym]-150;
BeginTokenList[ParamStack↑[ INT[CurInput.LimitField]+CurSym-(2392)],9];
 GOTO Label20; END--:676-- ELSE BEGIN CurCmd←38;
CurMod←ParamStack↑[ INT[CurInput.LimitField]+CurSym-(2242)];CurSym←0;
 GOTO Label10; END; END  ELSE IF  INT[CurInput.LocField]>0  THEN--677:
BEGIN IF Mem[CurInput.LocField]↑.Hh.B1=12  THEN BEGIN CurMod←Mem[
 INT[CurInput.LocField]+1]↑.Int;
IF Mem[CurInput.LocField]↑.Hh.B0=16  THEN CurCmd←42  ELSE BEGIN CurCmd
←39;
BEGIN IF  INT[StrRef↑[CurMod]]<127  THEN StrRef↑[CurMod]←StrRef↑[CurMod]+1;
 END; END; END  ELSE BEGIN CurMod←CurInput.LocField;CurCmd←38; END;
CurInput.LocField←Mem[CurInput.LocField]↑.Hh.Rh; GOTO Label10; END--:677
 ELSE BEGIN EndTokenList[]; GOTO Label20; END--:675--;--667:
CurCmd←Eqtb↑[CurSym].Lh;CurMod←Eqtb↑[CurSym].Rh;
IF  INT[CurCmd]>=83  THEN IF CheckOuterValidity [] THEN CurCmd←CurCmd-83
 ELSE  GOTO Label20--:667--;EXITS Label10 => NULL};EXIT; EXITS Label20 => NULL} ENDLOOP; END;--:666----681:-- 
 FirmUpTheLine: PROCEDURE = 
BEGIN K:PascalInteger[0..BufSize]; CurInput.LimitField←Last;
IF Internal↑[31]>0  THEN IF  INT[Interaction]>1  THEN BEGIN PrintLn[];
IF  INT[CurInput.StartField]<CurInput.LimitField  THEN FOR i:INT    IN [ INT[CurInput.
StartField ].. INT[ INT[CurInput.LimitField]-1 ]] DO  K ← i; Print[Buffer↑[K]] ENDLOOP;
First←CurInput.LimitField;BEGIN Print[520];TermInput[]; END;
IF  INT[Last]>First  THEN BEGIN FOR i:INT    IN [ INT[First ].. INT[Last-1 ]] DO  K ← i; Buffer↑[ INT[K]+CurInput.
StartField-First]←Buffer↑[K] ENDLOOP;
CurInput.LimitField← INT[CurInput.StartField]+Last-First; END; END; END;
--:681----684:-- ScanToks: PROCEDURE[Terminator: CommandCode,
SubstList,TailEnd: Halfword,SuffixCount: SmallNumber] RETURNS[ScanToksResult: Halfword]
 = 
BEGIN  P:Halfword;Q:Halfword;Balance:PascalInteger; P←49999;
Balance←1;Mem[49999]↑.Hh.Rh←0;{WHILE TRUE DO BEGIN GetNext[];
IF  INT[CurSym]>0  THEN BEGIN--685:--BEGIN Q←SubstList;
{WHILE Q#0 DO BEGIN IF Mem[Q]↑.Hh.Lh=CurSym  THEN BEGIN CurSym←Mem[ INT[Q]+1]↑
.Int;CurCmd←7; GOTO Label40; END;Q←Mem[Q]↑.Hh.Rh; END ENDLOOP ;EXITS Label40 => NULL}; END--:685--;
IF CurCmd=Terminator  THEN--686:
IF CurMod>0  THEN Balance←Balance+1  ELSE BEGIN Balance←Balance-1;
IF Balance=0  THEN  GOTO Label30; END--:686-- ELSE IF CurCmd=61  THEN--689:
BEGIN IF CurMod=0  THEN GetNext [] ELSE IF CurMod<=SuffixCount  THEN
CurSym←2391+CurMod; END--:689--; END;Mem[P]↑.Hh.Rh←CurTok[];
P←Mem[P]↑.Hh.Rh; END ENDLOOP ;EXITS Label30 => NULL};Mem[P]↑.Hh.Rh←TailEnd;
FlushNodeList[SubstList];ScanToksResult←Mem[49999]↑.Hh.Rh; END;--:684----690:
 GetSymbol: PROCEDURE = 
BEGIN  DO {--Label20:--GetNext[];
IF(CurSym=0)OR ( INT[CurSym]>2229) THEN BEGIN BEGIN IF Interaction=3  THEN NULL;
PrintNl[133];Print[532]; END;BEGIN HelpPtr←3;HelpLine↑[2]←533;
HelpLine↑[1]←534;HelpLine↑[0]←535; END;
IF  INT[CurSym]>0  THEN HelpLine↑[2]←536  ELSE IF CurCmd=39  THEN BEGIN IF
 INT[StrRef↑[CurMod]]<127  THEN IF  INT[StrRef↑[CurMod]]>1  THEN StrRef↑[CurMod]←
StrRef↑[CurMod]-1  ELSE FlushString[CurMod]; END;CurSym←2229;
InsError[]; GOTO Label20; END;EXIT; EXITS Label20 => NULL} ENDLOOP; END;--:690----691:--
END.