PalToTTT.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Last Edited by: Gasbarro July 13, 1987 6:40:49 pm PDT
DIRECTORY
CommandTool, FS, IO, Rope;
PalToTTT: CEDAR PROGRAM
IMPORTS CommandTool, FS, IO, Rope
~ BEGIN
ROPE: TYPE = Rope.ROPE;
Convert: PROC [inputs: LIST OF Rope.ROPE, fileName: ROPE, noOutputs: NAT] ~ {
PutLine: PROC [] ~ {
count: NAT ← 0;
FOR iList: LIST OF ROPE ← inputs, iList.rest WHILE iList#NIL DO
FOR tList: LIST OF term ← termList, tList.rest WHILE tList#NIL DO
IF Rope.Equal[iList.first, tList.first.r] THEN {
IO.PutChar[out, IF tList.first.a THEN '1 ELSE '0];
EXIT;
};
REPEAT
FINISHED => IO.PutChar[out, '.];
ENDLOOP;
count ← count+1;
IF count MOD 4 =0 THEN IO.PutChar[out, ' ];
ENDLOOP;
IO.Put[out, IO.rope[" | "]];
FOR i: NAT IN [0..noOutputs) DO
IO.PutChar[out, IF i=output THEN '- ELSE '1]
ENDLOOP;
IO.PutChar[out, '\n];
termList ← NIL;
};
GetExp: PROC [] ~ {
flag: BOOL;
termList ← NIL;
DO
rope ← IO.GetTokenRope[in].token;
IF Rope.Equal[rope, "+"] THEN PutLine[];
IF Rope.Equal[rope, "="] THEN {
PutLine[];
output ← output+1;
EXIT;
};
IF Rope.Equal[rope, "/"] THEN {
flag ← FALSE;
rope ← IO.GetTokenRope[in].token;
} ELSE flag ← TRUE;
termList ← CONS[NEW[termRec ← [rope, flag]], termList];
ENDLOOP;
IO.PutChar[out, '\n];
};
in: IO.STREAMFS.StreamOpen[fileName: fileName, accessOptions: $read, wDir: CommandTool.CurrentWorkingDirectory[]];
out: IO.STREAMFS.StreamOpen[fileName: Rope.Concat[Rope.Substr[fileName, 0, Rope.Find[fileName, "."]], ".ttt"], accessOptions: $create, wDir: CommandTool.CurrentWorkingDirectory[]];
rope: Rope.ROPE;
term: TYPE = REF termRec;
termRec: TYPE = RECORD [r: ROPE, a: BOOL];
termList: LIST OF term;
output: NAT ← 0;
DO
IF Rope.Equal[(rope ← IO.GetTokenRope[in].token), "^"] THEN GetExp[];
IF Rope.Equal[rope, "END"] THEN EXIT;
ENDLOOP;
IO.Close[in]; IO.Close[out];
};
END.