<> <> <> 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.STREAM _ FS.StreamOpen[fileName: fileName, accessOptions: $read, wDir: CommandTool.CurrentWorkingDirectory[]]; out: IO.STREAM _ FS.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.