Ein kleiner Pascal PrettyPrinter

Ein Programm zum "Pretty-Printen" von PASCAL-Source-Code.
PROGRAM prettyPrinter(input,output);
{ Version 1.0 }
CONST MAXLEN   = 15;
      GROSS    = ['A'..'Z'];
      KLEIN    = ['a'..'z'];
TYPE  tString = string[MAXLEN];
VAR   inFile,
      outFile      : text;

procedure readword(var inFile : text; var inString : tString);
var ch : char; EOW : boolean;
begin
  EOW:= EOF(inFile); inString:= '';
  while not EOW do
    begin
      read(inFile,ch); inString:= concat(inString,ch);
      if not (ch in GROSS+KLEIN) then EOW:= TRUE;
    end
end;

PROCEDURE convert(inWord : tString; var outWord:tString);
VAR n  : integer;
BEGIN
  outWord:= inWord;
  FOR n:= 1 TO length(outWord) DO
    IF outWord[n] in KLEIN THEN
      BEGIN
       outWord[n]:= chr(ord('A')+ord(outWord[n])-ord('a'));
      END;
END; { convert }

FUNCTION keyWord(inWord:tString):boolean;
BEGIN
  IF (inWord = 'PROGRAM')    or (inWord = 'CONST')     or
     (inWord = 'CONST')      or (inWord = 'LABEL')     or
     (inWord = 'LABEL')      or (inWord = 'TYPE')      or
     (inWord = 'VAR')        or (inWord = 'PROCEDURE') or
     (inWord = 'FUNCTION')   or (inWord = 'BEGIN')     or
     (inWord = 'END')        or (inWord = 'CASE')      or
     (inWord = 'OF')         or (inWord = 'IF')        or
     (inWord = 'THEN')       or (inWord = 'ELSE')      or
     (inWord = 'GOTO')       or (inWord = 'FOR')       or
     (inWord = 'TO')         or (inWord = 'DOWNTO')    or
     (inWord = 'REPEAT')     or (inWord = 'UNTIL')     or
     (inWord = 'WHILE')      or (inWord = 'DO')        or

     (inWord = 'ALGORITHM')  or (inWord = 'OD')        or
     (inWord = 'FI')         or (inWord = 'DO')        or
     (inWord = 'ALGEBRA')    or (inWord = 'OPS')       or
     (inWord = 'SETS')       or (inWord = 'FUNCTIONS')
  THEN
    keyWord:= TRUE
  ELSE
    keyWord:= FALSE;
END; { keyWord }

PROCEDURE scanFile(VAR inFile:text);
VAR word,
    outWord    : tString;
    n          : integer;
    lastchar   : char;
BEGIN
  WHILE (not(EOF(inFile))) DO
    BEGIN
      readWord(inFile,word);
      lastchar:= word[length(word)];
      word:= copy(word,1,length(word)-1);
      convert(word,outWord);
      if keyWord(outWord) then write(outFile,outWord)
      else write(outFile,word);
      write(outFile,lastchar);
    END
END; { scanFile }

begin  { PROGRAM }
  assign(inFile,paramstr(1));  reset(inFile);
  assign(outFile,paramstr(2)); rewrite(outFile);
  scanFile(inFile);
  close(inFile); close(outFile);
END.

Alle Touren

Schneebergwege

Raxsteige

Geführte Touren

Perl

Literatur

Musik