Z Language
(Basic)
Back
to Summary
> A Z algorithm is a set of modules. The first one is the main module and the others are either actions (ACTION) or functions (FUNCTION).
> The Z language accepts recursion.
> Static objects are declared in the main module.
> The communication between modules is made via parameters and static variables.
> The language allows:
- Any type of parameters : scalars, structures, linked lists , queues, stacks, arrays, trees and also complex types.
- The dynamic allocation of arrays and structures
- The global assignment of any type
> Four standard types ( scalars) are allowed : INTEGER, BOOLEAN, CHAR, STRING .
> Some usual functions exist : MOD, MAX, MIN, RANDNUMBER, RANDSTRING,...
> The langage is the set of abstract algorithms written by using abstract machines.
> So, we considere abstract machines on structures, arrays of any dimension, queues, stacks, binary and m-ary search trees, linked lists and bidrectional linlked lists.
> We also consider an abstract machine on the files allowing their use and the construction of simple structures of files as well as the most complex structures.
> The language allows compound types such as STACK OF QUEUE OF LISTS OF ....of which the last one quoted is of scalar type or simple structure.
> The language has high-level operations to build lists, trees, queues, etc. from a set of values ( expressions ) or structures.
> the language offers two very useful functions to randomly generate strings (ALEACHAINE) and integers (ALEANUMBER).
> The language allows reading and writing scalars, n-dimensional arrays of scalars and simple or complex structures.
LET
{ Local and statitc objects }
{ announcement of the modules}
BEGIN
{ Statements }
END
Module 1
....
Module n
Each module can be either a function or an action.
While loop
WHILE E [ : ]
{ Statements }
ENDWHILE
For loop
FOR V := E1, E2 [,E3]
{ Statements }
ENDFOR
E3, if present, designates the step.
Conditional
IF E [ : ]
{ Statements }
[ ELSE
{ Statements } ]
ENDSI
V denotes a variable, E an expression and Idf a module identifier.
Assignment : V := E
Reading : READ(V1, V2, .....)
Variables can be scalars, structures or arrays of any dimension.
Writing : WRITE(E1, E2, .....)
Expressions can be scalars, structures or n-dimensional arrays.
Quatre types standards sont autorisés : INTEGER, CHAR, STRING, BOOLEAN.
Definition of scalars
LET <li> Sep Type
<Li> : identifier list separated by coma.
Type is a standard type.
Examples
A, B, Found : BOOLEANS ;
A : INTEGER ;
X, Y, Z : STRINGS ;
We define pointer variables to use data structures.
LET <li> : POINTER TO Typec [ OF Typec OF Typec OF ....] [ OF Types]
<Li> : Identifier list separated by coma.
Typec in { ARRAY, STACK, list, QUEUE, BST, BIlist, MST }
Types is a scalar or simple structure.
Note
We can do not use the pointer type. Indeed, declarations
"LET L : list" and
"LET L : pointer TO list"
are equivalent.
Examples
P1 : POINTER TO LIST OF STACKS;
P2, P2 : POINTERS TO BST;
As in the programming languages.
Arithmetical expressions : + , - , / , *
Logical expressions : AND, OR, NOT
Expressions on strings : +
Relational expressions : <, <=, >, >=, =, <> (ou #)
Logical constants : TRUE, FALSE
Pointer constant : NULL
Examples
B+C / F
NOT Found
(X # 5) AND NOT Found
F(X) <> 5
P = Null
Comments are inserted into any place where we can insert a space.
Comments are beteween { and } or beteween /* and */.
The Z language has high-level operations for filling or initializing a data structure from a set of values.
CREATE_ARB, CREATE_LISTE, CREATE_LISTEBI, CREATE_ARM, CREATE_PILE, CREATE_FILE, INIT_VECT (or INIT_ARRAY), INIT_STRUCT
Syntax :
CREATE_LIST ( L, [Exp1, Exp2, ....] )
CREATE_BILIST ( LB, [Exp1, Exp2, ....] )
CREATE_BST ( A, [Exp1, Exp2, ....] )
CREATE_MST ( M, [Exp1, Exp2, ....] )
CREATE_QUEUE ( F, [Exp1, Exp2, ....] )
CREATE_STACK ( P, [Exp1, Exp2, ....] )
INIT_STRUCT(S, [Exp1, Exp2, ....])
INIT_ARRAY ( T, [Exp1, Exp2, ....] )
Exp1, Exp2, .... are scalar expressions or structures.
Examples
CREATE-LIST (L, [12, 23, 67, I, I+J] )
creates the linked list L with values with the values in square brackets in the order shown.
If L1 and L2 are 2 integer linked list and Ll a linked list of a linked list of integers, we can then write :
CREATE_LIST ( L1 , [ 2 , 4 , 67 , 778 ] ) ;
CREATE_LIST ( L2 , [ 12 , 14 , 167 , 1778 ] ) ;
CREATE_LIST ( Ll , [ L1 , L2 ] ) ;
MOD (A, B) : Give the remainder of the integer division of A by B.
MAX(A, B) : Give the maximum between A and B.
MIN(A, B) : Give the minimum between A and B.
EXP(A, B) : A exposant B
Fonctions de
génération aléatoire
RANDSTRING(N) : Generate an alphanumeric string of N characters.
RANDNUMBER (N) : Generate an integer between 0 and N.
CHARACT(S, I) : give the i-th character of the string S.
LENTHSTRING(S) : give the length of string S
ACTION Name (P1, P2, ..., Pn)
Calling an action is made by the operation CALL followed by the name of the action and its parameters.
Parameters are not protected by the action.
FUNCTION Name (P1, P2, ...,Pn) : Type
Type can be any.
Functions are used in expressions.
Parameters are not protected by the function.