%*************************************************************** % A simple enviroment for use of Dirac interpreter parse.m % Because of global variable management it can be re-entered % % initilize: Dirac % by entering H: or h: or ? you get help % by entering $ : exit %*************************************************************** format compact warning off ShowMat=0; blanc=' '; global GLOBALIZE; global DECLARED; global InitDirac; if size(InitDirac) == [0 0] GLOBALIZE='global FileHnd ;'; DECLARED=''; FileHnd=fopen('Dirac.cmd','w'); InitDirac=1; else fprintf(1,'Declared: %s\n', DECLARED) FileHnd=fopen('Dirac.cmd','a'); end stopval=0; while stopval==0 eval(GLOBALIZE); InputStr=input('Dirac : ','s'); done=0; leng=length(InputStr); if( leng<1) InputStr='% '; leng=length(InputStr); done=1; end % cosmetics: remove blancs etc. while findstr(InputStr,[blanc blanc])~=[] InputStr=strrep(InputStr,[blanc blanc],blanc); end %remove blanc at beginning and end if InputStr(length(InputStr))==blanc InputStr=InputStr(1:length(InputStr)-1) ; end if InputStr(1)==blanc InputStr=InputStr(2:length(InputStr)) ; end % cosmetics done leng=length(InputStr); if InputStr(1:1) == '$' stopval=1; fclose( FileHnd); done=1; else if( leng<1) InputStr='%' done=1; end if InputStr(1) == '?' ! cat DiracHelp.txt done=1; end if InputStr(1) == '%' fprintf( FileHnd,'%s\n',InputStr); done=1; end Procent= findstr(InputStr,'%'); if Procent ~= [] if done~=1 fprintf( FileHnd,'%s\n',InputStr(Procent(1):leng)); end InputStr=InputStr(1:Procent(1)-1); end if(leng>1 & done~=1 ) if strcmp(InputStr(1:2),'D:')==1 fprintf( FileHnd,'%s\n',InputStr); InputStr=InputStr(3:leng); Declare(InputStr); % is in Declare.m DECLARED=[DECLARED InputStr ' ' ]; eval(GLOBALIZE); done=1; elseif strcmp(InputStr(1:2),'M:')==1 fprintf( FileHnd,'%s\n',InputStr); InputStr=InputStr(3:leng); eval(InputStr); done=1; elseif strcmp(InputStr(1:2),'H:')==1 krise=[ '! cat ' pwd '/DiracHelp.txt' ]; eval(krise); done=1; elseif strcmp(InputStr(1:2),'h:')==1 krise=[ '! more ' pwd '/DiracHelp.txt' ]; eval(krise); done=1; elseif strcmp(InputStr(1:2),'e:')==1 krise=[ '!more ' pwd '/example2.txt']; done=1; eval(krise); elseif strcmp(InputStr(1:2),'E:')==1 krise=[ '! more ' pwd '/example3.txt']; eval(krise); done=1; elseif strcmp(InputStr(1:2),'G:')==1 fprintf(1,'Statement: %s\n\n', GLOBALIZE) fprintf(1,'Declared : %s\n', DECLARED) done=1; elseif strcmp(InputStr(1:2),'S:')==1 if(ShowMat==0) ShowMat=1; fprintf(1,'Showing Matlab Command: Now ON \n') else ShowMat=0; fprintf(1,'Showing Matlab Command: Now OFF \n') end done=1; elseif strcmp(InputStr(1:2),'c:')==1 more on krise=[ '! more ' pwd '/Dirac.cmd']; eval(krise); more off done=1; end end if done ~= 1 fprintf( FileHnd,'%s\n',InputStr); OutStr=parse(InputStr); if(ShowMat==1) fprintf(1,'Matlab: --> %s\n',OutStr); end eval(OutStr); end end % if not stop ( stopval=1; ) end % while