Program lab4; uses crt; var s:string; pos:byte; e:boolean; Procedure Ident; {Identificator } begin inc(pos); if (upcase(s[pos]) in ['A'..'Z'])and(not e) then begin while (upcase(s[pos]) in ['A'..'Z','0'..'9'])and(pos<=length(s)) do inc(pos); end else e:=true; end; Procedure IndVyr; begin if (upcase(s[pos]) in ['A'..'Z'])and(not e) then inc(pos) {Esli est identificator, to vse OK} else begin if (s[pos]='(') then {Esli est' '(' znachit budet neskolko identificatorov} begin pos:=pos+1; IndVyr; if s[pos] in ['+','-','*'] then while s[pos] in ['+','-','*'] do begin {Dolgen byt' znak operaciy} inc(pos); IndVyr; {Sleduyshiy identificator} end;
if s[pos]<>')' then e:=true else inc(pos); end else e:=true; end; end; Procedure ListIdent; {Spisok identificatorov - proveryaet na pravylnost} begin if not e then IndVyr; while (not e)and( s[pos]=',') do begin inc(pos); IndVyr;{Esli imeem zapyatuu proveryaem} end; {sleduushie identificatory} end; Procedure IndexPerem; {Proverka} begin while (pos<=length(s))and(not e) do {Poka ne konec stroky} begin Ident; {Proveryaem pravylnost identificatora} if (pos<length(s))and(s[pos]='[')and(not e) then begin pos:=pos+1; ListIdent; {Proveryaem spisok identificatorov} if (pos<=length(s))and(s[pos]=']') then inc(pos) {Esli ne conec vyrageniya, smotrym dalshe} else e:=true; end else e:=true; end; end; begin clrscr; writeln('Input PROGRAM'); readln(s); for pos:=1 to length(s) do if s[pos]=' ' then delete(s,pos,1); e:=false; pos:=0; IndexPerem; if e=false then writeln('CORRECT') {Vyvod otveta} else writeln('ERROR'); readln; end.
|