program pretty(input,output);
kinds = (ident, number, op, endfile);
symb = array[1..SYMLENGTH] of char;
working, space, indentflag: boolean;
procflag, inparam, caseflag: boolean;
for i := 1 to tabs do write(' ');
procedure writesym(a:scanres);
if indentflag then indent;
if (a.kind = ident) and space then write(' ');
if (a.kind = op) and (a.symbol[1] in ['(','+','-','*']) then write(' ');
while (a.symbol[i] <> ' ') do
if a.kind <> ident then space := false else space := true;
if (a.kind = op) and (a.symbol[1] in [')','+','-','*']) then write(' ');
function scanner:scanres;
for i := 1 to SYMLENGTH do Scanner.symbol[i] := ' ';
while (ch in [' ', ' ']) and (not eof(input)) do
if eof(input) then Scanner.kind := endfile
if ch in ['a'..'z', 'A'..'Z'] then { identifiers }
while ch in ['a'..'z', 'A'..'Z', '0'..'9'] do
else if ch in ['0'..'9'] then { numbers }
while ch in ['0'..'9'] do
if ch in ['<','>',':'] then
function compar(s1:symb; s2:symb):boolean;
while (comp and (i <= SYMLENGTH)) do
comp := comp & (s1[i] = s2[i]);
if compar(a.symbol, 'begin') then
else if compar(a.symbol, 'case') then
else if compar(a.symbol, 'procedure') or
compar(a.symbol, 'function') then
else if compar(a.symbol, 'var') or
compar(a.symbol, 'type') or
compar(a.symbol, 'const') or
compar(a.symbol, 'label') then
else if compar(a.symbol, 'of') then
else if compar(a.symbol, 'record') then
else if compar(a.symbol, 'end') then
if a.symbol[1] = '''' then
else if a.symbol[1] = ';' then
else if (a.symbol[1] = '(') & procflag then
else if a.symbol[1] = ')' then