Steps
to follow for the realization of a program under K H A W A R I Z M
Back
to Summary
Familiarization with an arbitrary algorithmic language
Familiarization
with an arbitrary algorithmic language
Learn the
algorithmic language used.
Use the online help.
Write an algorithm or correct an existing algorithm.
Run the arranger module.
Repeat as long as there are errors
. Correct the errors
. Relaunch the arranger module
At this point, your algorithm is well written and has been indented for you.
(You can change the presentation modes of your algorithm (see "Options" in
the menu)
Start
the execution of your algorithm
The windows then show
- the data read by your algorithm ( Data button )
- the writings emitted by your algorithm (Button Results)
Your algorithm gives either the expected results or not. In this last case,
launch the simulation to try to determine the logic errors.
Run the simulation of your
algorithm.
This is an execution with a trace.
The windows show
- the data read by your algorithm (Data button)
- the writings issued by your algorithm ( Button Results )
- all the changes made on the objects used ( Button Simulation )
You thus have the complete trace of your algorithm that you can print and
analyze to detect errors.
If you want to see more closely the different steps of your algorithm, ask
for a trace.
Request
the simulation with trace again.
You can then follow step by step the evolution of your algorithm, exit the
current loop or even the current module.
In order to avoid having a complete trace which can be long, it is possible
to limit the length of the loops used in your algorithm. You can change the
simulation modes (see "Options" in the menu).
Translation to
a programming language
Once your algorithm is "running", it is possible to translate it automatically
into PASCAL or C. Just click on the "To Pascal" or "To C" button. Two
windows organized as "Tiles" are then shown. One contains your algorithm and
the other the result of the translation.
You can consult the help concerning the transition to PASCAL or C.
In this help, you will find
- the Z to PASCAL and Z to C equivalents.
- All implementations of Z machines.
Khawarizm's task stops here.
Use the
PASCAL or C compiler to finalize your program. In particular, you can add
all the procedures of data entry and restitution of the results.
{ Is a liked list
included in another ? }
LET
L1 , L2 : LISTS ;
Search , All : FUNCTION ( BOOLEAN ) ;
BEGIN
CREATE_LIST ( L1 , [ 2 , 5 , 9 , 8 , 3 , 6 ] ) ;
CREATE_LIST ( L2 , [ 12 , 5 , 19 , 8 , 3 , 6 , 2 , 9 ] ) ;
WRITE ( All ( L1 , L2 ) )
END
{ Search for a value in a linked list }
FUNCTION Search ( L , Val ) : BOOLEAN
LET
L : LIST ;
Val : INTEGER ;
BEGIN
IF L = NULL
Search := FALSE
ELSE
IF CELL_VALUE ( L ) = Val
Search := TRUE
ELSE
Search := Search ( NEXT ( L ) , Val )
ENDIF
ENDIF
END
{ Is L1 included in L2? }
FUNCTION All ( L1 , L2 ) : BOOLEAN
LET
L1 , L2 : LISTS ;
BEGIN
IF L1 = NULL
All := TRUE
ELSE
IF NOT Search ( L2 , CELL_VALUE ( L1 ) )
All := FALSE
ELSE
All := All ( NEXT ( L1 ) , L2 )
ENDIF
ENDIF
END
{**--------------------------------------------------------**/
/** T r a n s l a t i o n Z to PASCAL (Standard) **/
/** By Pr. D.E ZEGOUR **/
/** E S I - Algier **/
/** Copywrite 2014 **/
/**--------------------------------------------------------**}
PROGRAM My_program;
{ Implementation : LIST Of INTEGERS}
{ Linked lists }
TYPE
Typeelem_LI = INTEGER;
Pointer_LI = ^Maillon_LI; { type du champ 'Adresse' }
Maillon_LI = RECORD
Val : Typeelem_LI;
Next : Pointer_LI
END;
PROCEDURE Allocate_cell_LI ( VAR P : Pointer_LI ) ;
BEGIN NEW(P) END;
PROCEDURE Free_LI ( P : Pointer_LI ) ;
BEGIN DISPOSE(P) END;
PROCEDURE Ass_val_LI(P : Pointer_LI; Val : Typeelem_LI );
BEGIN P^.Val := Val END;
FUNCTION Cell_value_LI (P : Pointer_LI) : Typeelem_LI;
BEGIN Cell_value_LI := P^.Val END;
FUNCTION Next_LI( P : Pointer_LI) : Pointer_LI;
BEGIN Next_LI := P^.Next END;
PROCEDURE Ass_adr_LI( P, Q : Pointer_LI ) ;
BEGIN P^.Next := Q END;
TYPE
Typeelem_V6I = INTEGER ;
Typetab_V6I = ARRAY[1..6] of Typeelem_V6I ;
TYPE
Typeelem_V8I = INTEGER ;
Typetab_V8I = ARRAY[1..8] of Typeelem_V8I ;
{ Declaration part of variables }
VAR
L1 : Pointer_LI;
L2 : Pointer_LI;
T_L1 : Typetab_V6I ;
T_L2 : Typetab_V8I ;
{ High level operations }
{ creating a linked list }
PROCEDURE Create_list_LI ( VAR L : Pointer_LI ; Tab : Typetab_V6I ; N:
INTEGER) ;
VAR
I : INTEGER;
P, Q : Pointer_LI ;
BEGIN
L:=NIL;
FOR I := 1 TO N DO
BEGIN
Allocate_cell_LI( Q ) ;
Ass_val_LI (Q, Tab[I]);
Ass_adr_LI (Q, NIL);
IF L = NIL
THEN L := Q
ELSE Ass_adr_LI (P, Q);
P := Q
END;
END;
{ Procedure and/or function prototypes }
FUNCTION Search (VAR L : Pointer_LI ; VAR Val : INTEGER) : BOOLEAN; FORWARD;
FUNCTION All (VAR L1 : Pointer_LI ; VAR L2 : Pointer_LI) : BOOLEAN; FORWARD;
{ Search for a value in a linked list }
FUNCTION Search (VAR L : Pointer_LI ; VAR Val : INTEGER) : BOOLEAN;
{ Declaration part of variables }
VAR
Search2 : BOOLEAN ;
_Px1 : Pointer_LI;
BEGIN
IF L = NIL THEN BEGIN
Search2 := FALSE END
ELSE
BEGIN
IF Cell_value_LI(L ) = Val THEN BEGIN
Search2 := TRUE END
ELSE
BEGIN
_Px1 := Next_LI(L ) ;
Search2 := Search (_Px1, Val )
END
END
;Search := Search2 ;
END;
{ Is L1 included in L2? }
FUNCTION All (VAR L1 : Pointer_LI ; VAR L2 : Pointer_LI) : BOOLEAN;
{ Declaration part of variables }
VAR
All2 : BOOLEAN ;
_Px1 : INTEGER ;
_Px2 : Pointer_LI;
BEGIN
IF L1 = NIL THEN BEGIN
All2 := TRUE END
ELSE
BEGIN
_Px1 := Cell_value_LI(L1 ) ;
IF NOT Search ( L2 ,_Px1) THEN BEGIN
All2 := FALSE END
ELSE
BEGIN
_Px2 := Next_LI(L1 ) ;
All2 := All (_Px2, L2 )
END
END
;All := All2 ;
END;
{ Body of main program }
BEGIN
T_L1 [ 1 ] := 2 ;
T_L1 [ 2 ] := 5 ;
T_L1 [ 3 ] := 9 ;
T_L1 [ 4 ] := 8 ;
T_L1 [ 5 ] := 3 ;
T_L1 [ 6 ] := 6 ;
Create_list_LI ( L1 , T_L1 , 6 ) ;
T_L2 [ 1 ] := 12 ;
T_L2 [ 2 ] := 5 ;
T_L2 [ 3 ] := 19 ;
T_L2 [ 4 ] := 8 ;
T_L2 [ 5 ] := 3 ;
T_L2 [ 6 ] := 6 ;
T_L2 [ 7 ] := 2 ;
T_L2 [ 8 ] := 9 ;
Create_list_LI ( L2 , T_L2 , 8 ) ;
WRITELN ( All(L1,L2) )
;READLN;
END.
/**--------------------------------------------------------**/
/** T r a n s l a t i o n Z to C (Standard) **/
/** By Pr. D.E ZEGOUR **/
/** E S I - Algier **/
/** Copywrite 2014 **/
/**--------------------------------------------------------**/
/* Is a liked list included in another ? */
#include <stdio.h>
#include <stdlib.h>
typedef int bool ;
#define True 1
#define False 0
/** -Implementation- **\: LIST Of INTEGERS**/
/** Linked lists **/
typedef int Typeelem_Li ;
typedef struct Maillon_Li * Pointer_Li ;
struct Maillon_Li
{
Typeelem_Li Val ;
Pointer_Li Next ;
} ;
Pointer_Li Allocate_cell_Li (Pointer_Li *P)
{
*P = (struct Maillon_Li *) malloc( sizeof( struct Maillon_Li)) ;
(*P)->Next = NULL;
}
void Ass_val_Li(Pointer_Li P, Typeelem_Li Val)
{
P->Val = Val ;
}
void Ass_adr_Li( Pointer_Li P, Pointer_Li Q)
{
P->Next = Q ;
}
Pointer_Li Next_Li( Pointer_Li P)
{ return( P->Next ) ; }
Typeelem_Li Cell_value_Li( Pointer_Li P)
{ return( P->Val) ; }
void Free_Li ( Pointer_Li P)
{ free (P);}
/** For temporary variables **/
typedef int Typeelem_V6i;
typedef Typeelem_V6i Typetab_V6i[6];
/** For temporary variables **/
typedef int Typeelem_V8i;
typedef Typeelem_V8i Typetab_V8i[8];
/** Variables of main program **/
Pointer_Li L1=NULL;
Pointer_Li L2=NULL;
Typetab_V6i T_L1;
Typetab_V8i T_L2;
/** High level operations **/
/** creating a linked list **/
void Create_list_Li ( Pointer_Li *L, Typetab_V6i Tab, int N)
{
int I ;
Pointer_Li P, Q ;
*L =NULL;
for( I=1;I<=N;++I)
{
Allocate_cell_Li( &Q ) ;
Ass_val_Li (Q, Tab[I-1]);
Ass_adr_Li (Q, NULL);
if (*L == NULL)
*L = Q ;
else Ass_adr_Li (P, Q);
P = Q ;
}
}
/** Function prototypes **/
bool Search (Pointer_Li *L , int *Val) ;
bool All (Pointer_Li *L1 , Pointer_Li *L2) ;
/* Search for a value in a linked list */
bool Search (Pointer_Li *L , int *Val)
{
/** Local variables **/
bool Search2 ;
Pointer_Li _Px1=NULL;
/** Body of function **/
if( *L == NULL) {
Search2 = False; }
else
{
if( Cell_value_Li ( *L ) == *Val) {
Search2 = True; }
else
{
_Px1 = Next_Li ( *L ) ;
Search2 = Search ( &_Px1, & *Val );
}
}
return Search2 ;
}
/* Is L1 included in L2? */
bool All (Pointer_Li *L1 , Pointer_Li *L2)
{
/** Local variables **/
bool All2 ;
int _Px1;
Pointer_Li _Px2=NULL;
/** Body of function **/
if( *L1 == NULL) {
All2 = True; }
else
{
_Px1 = Cell_value_Li ( *L1 ) ;
if( ! Search ( & *L2 , &_Px1)) {
All2 = False; }
else
{
_Px2 = Next_Li ( *L1 ) ;
All2 = All ( &_Px2, & *L2 );
}
}
return All2 ;
}
int main(int argc, char *argv[])
{
T_L1 [ 0 ] = 2 ;
T_L1 [ 1 ] = 5 ;
T_L1 [ 2 ] = 9 ;
T_L1 [ 3 ] = 8 ;
T_L1 [ 4 ] = 3 ;
T_L1 [ 5 ] = 6 ;
Create_list_Li (&L1 , T_L1 , 6 ) ;
T_L2 [ 0 ] = 12 ;
T_L2 [ 1 ] = 5 ;
T_L2 [ 2 ] = 19 ;
T_L2 [ 3 ] = 8 ;
T_L2 [ 4 ] = 3 ;
T_L2 [ 5 ] = 6 ;
T_L2 [ 6 ] = 2 ;
T_L2 [ 7 ] = 9 ;
Create_list_Li (&L2 , T_L2 , 8 ) ;
printf ( " %d", All(&L1,&L2) );
system("PAUSE");
return 0;
}