Стили и методы программирования




Пример 10.2.4


program funcgoto;

{$APPTYPE CONSOLE} {$T+}

uses SysUtils;

type P=procedure;

type Pp= ^P;

const maxstate = 7;

const maxcond = 3;

type states = 1.. maxstate;

conds = 1.. maxcond;

type table = array [states, conds] of states;

type act = array [states] of P;

const gotos: table = ((2,2,2),(3,2,4),(3,5,6),(3,2,7),(3,2,4),(3,2,7),(1,1,1));

var Symbol: char;

var Cnt: integer;

var Inf, Outf: text;

var state: states;

procedure Start;

begin

Cnt:=0;

AssignFile(Inf, 'input.txt');

Reset(Inf);

AssignFile(Outf, 'output.txt');

Rewrite(Outf);

end;

procedure Finish;

begin

Closefile(Inf);

Closefile(Outf);

Abort;

end;

procedure St1;

begin

{No actions}

end;

procedure St2;

begin

write(outf,Symbol);

Inc(Cnt);

end;

procedure St4;

begin

writeln(outf,' - ',Cnt);

Cnt:=0;

end;

const actions: act = (Start, St1,St2,St1,St4,St4,Finish);

begin

state:=1;

while true do begin

actions[state];

if (state <>1) and (state<>7) then begin read(inf,Symbol);

if Ord(Symbol)=10 then read(inf,Symbol) end;

if Symbol in ['a'..'z'] then state:= gotos[state,1];

if not(Symbol in ['a'..'z']) and (Ord(Symbol)<>13)

then state:=gotos[state,2];

if Ord(Symbol)=13 then state:=gotos[state,3];

end;

end.




Содержание  Назад  Вперед