|
ru.algorithms- RU.ALGORITHMS ---------------------------------------------------------------- From : Sergey Prohorenko 2:463/397 01 Jun 2003 22:59:46 To : Sergey Novikov Subject : Материалы и/или проги -------------------------------------------------------------------------------- 28 мая 2003 года Sergey Novikov в письме к All писал(а): SN> 1) Машина Поста Д интерпритатор Держи исходник. Можешь не спрашивать, что к чему, так как у нас это еще в начале второго курса было - уже с трудом вспоминается, что есть машина Поста :) === Цитирую === program Post; const config_name='post.cnf'; var current_word,current_vertix:string; delimiter:char; (* it denotes delimiter between chars and next vertix name in test vertices *) config_file,input_file,init_file,output_file:text; input_name,init_name,output_name:string; s1,s2:string; i:byte; vertix_name:string; vertix_type:char; ind,finishing:boolean; procedure error(message:string); (* finishing program because of error *) begin writeln(output_file); write(output_file,message, 'sorry, I cannot help you'); close(input_file); close(output_file); halt end; begin assign(config_file,config_name); reset(config_file); readln(config_file); (* skipping comment string *) readln(config_file,delimiter); readln(config_file,input_name); readln(config_file,init_name); readln(config_file,output_name); close(config_file); (*we don't more need config file *) assign(input_file,input_name); assign(output_file,output_name); reset(input_file); rewrite(output_file); (* we have two open files now: file to read (input_file) and file to write (output_file) *) assign(init_file,init_name); reset(init_file); readln(init_file,current_word); (* we suppose for initial word to be contained in the init file *) close(init_file); writeln(output_file,current_word); readln(input_file); (* skipping comment string *) repeat readln(input_file,current_vertix); current_vertix:=current_vertix+' '; (* to avoid unpleasant case of zero length *) until (current_vertix[1] in ['b','B']) or eof(input_file); (* searching for the start vertix *) if not (current_vertix[1] in ['b','B']) then error('I have not found start vertix; '); delete(current_vertix,length(current_vertix),1); (* to delete the space which we inserted at the end of current_vertix *) writeln(output_file,current_vertix); writeln(output_file,current_word); i:=pos(' ',current_vertix); if i=0 then error(' I have not found a body of the vertix ' +current_vertix+'; '); delete(current_vertix,1,i); vertix_name:=current_vertix; (* we have extracted the name of the next vertix *) finishing:=false; repeat reset(input_file); readln(input_file); (* skippimg comment string *) repeat readln(input_file,current_vertix); ind:=((pos(vertix_name+' ',current_vertix)=1) or ((pos(vertix_name,current_vertix)=1) and (length(vertix_name)=length(current_vertix)))) until ind or eof(input_file); (* searching for vertix name in the vertix list *) if not ind then error('I have not found vertix '+ vertix_name+ ' in the vertix list; '); writeln(output_file,current_vertix); i:=pos(' ',current_vertix); if (i=0) and not (vertix_name[1] in ['e','E']) then error(' I have not found a body of the vertix ' +current_vertix+'; '); delete(current_vertix,1,i); case vertix_name[1] of 't','T': begin current_vertix:=' '+current_vertix; if length(current_word)>0 then i:=pos(' '+current_word[1]+delimiter,current_vertix) else i:=pos(' '+delimiter,current_vertix); if i=0 then error('I have not found the first char of current word'+ ' in the test vertix '+vertix_name+'; '); delete(current_vertix,1,i); i:=pos(' ',current_vertix); if i>0 then delete(current_vertix,i,length(current_vertix)-i+1); if length(current_word)>0 then vertix_name:=copy(current_vertix,3,length(current_vertix)-2) else vertix_name:=copy(current_vertix,2,length(current_vertix)-1); delete(current_word,1,1); end; 'g','G': begin if current_vertix[2]<>' ' then error('invalid generated vertix '+vertix_name+ '; '); current_word:=current_word+current_vertix[1]; delete(current_vertix,1,2); vertix_name:=current_vertix end; 'e','E': begin vertix_name:=''; finishing:=true end else error('unknown vertix type '+vertix_name[1]+'; ') end; reset(output_file); repeat readln(output_file,s1); readln(output_file,s2); ind:=(current_word=s1) and (pos(vertix_name+' ',s2)=1) until ind or eof(output_file); append(output_file); (* checking output file for a cycle *) if ind then begin writeln(output_file,current_word); error('infinite cycle, Post machine doesn''t stop; ') end; (* finishing program because of infinite cycle*) writeln(output_file,current_word) until finishing; writeln(output_file); writeln(output_file,'I have finished succefully, bye-bye'); close(input_file); close(output_file) end. === Конец цитаты === SN> 2) Вычисление логических функций В инете полно должно быть. Have a nice life, Sergey ! [ronnie<at>ukrpost.net] [HТУУ КПИ ИПСА КА-95] ... Heap big woman you made a bad boy out of me [Queen] --- np: winamp is not active * Origin: Здесь каждую ночь совершается чудо ... (2:463/397) Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.algorithms/184513eda8663.html, оценка из 5, голосов 10
|