AMADEUS html plain
Program mapping
common principles
general
Any sketchy program is described in the first branch
of an outer sketch.
The type of the outer sketch and its other elements
(comment, head(s), additional branches) are insignificant.
For better structuring, bigger program constructs, such as classes,
modules, methods, functions, flow controls etc. may be represented
as subsketches (instead of plain-text bracing or keywording).
In the following section, common principles of sketchy representing for
control flow structures inside functions and procedures are introduced.
flow control
Simple and loop sketches are used to represent control flow
structures.
loops
In common, only loops with a single branch are used.
free loop
A loop sketch without head is called the free loop.
loop
branch
The branch describes one step of iteration. After the (normal)
completion of the branch, it will be executed again.
For terminating the free loop, conditions and/or arrows are
used (see below, sections "conditions" and "arrows").
head loop
A loop sketch with head is called the head loop. Usually,
it corresponds to a head-controlled loop in the base language.
So the head is a base language primitive for controlling the
repetition process.
loop
* . . .
head
branch
The branch describes one step of iteration. The number of
iterations is controlled by the head.
For extra termination of the head loop, conditions and arrows
are used (see below, sections "conditions" and "arrows").
conditions
Conditions are branch members written as
base language Boolean (bi-valent) expressions.
Any condition represents a semaphore:
when the current condition evaluates to TRUE,
then control flow passes through it
to the next member (or end of the branch);
otherwise a control flow jump occurs.
The jump, caused by a FALSE-condition t, is defined as follows.
Let B be the branch containing t as a member,
and S - the parent sketch of branch B.
If there exists at least one member-arrow in B downwards from t,
then
the jump destination point is just behind
the nearest downward arrow;
else
if parent sketch S is headless,
then S is exited;
else B is exited.
examples
jump behind arrow
(in the sketch of any type)
. . .
any code
? t1
condition
. . .
arrowless group of members
<======
arrow (of any kind and length)
jump destination point for t1 = FALSE
. . .
any code
break/contiunue
no arrows in the rest part, following the condition
headless sketch of any type
. . .
any code
? t2
breaks the scheme, if t2 = FALSE
. . .
arrowless group of members
loop with head
* . . .
. . .
any code
? t2
breaks the branch (continues the loop), if t2 = FALSE
. . .
arrowless group of members
simple sketch with head
. . .
. . .
any code
? t2
breaks the branch (continues next branch), if t2 = FALSE
. . .
arrowless group of members
arrows
Arrows are used to show breaks to outer levels.
examples
A (sketch at level 10)
B (branch at level 11)
<======
strong arrow, breaks A
<------
weak arrow, breaks B
C (sketch at level 12)
D (branch at level 13)
<======
strong arrow, breaks C
<------
weak arrow, breaks D
<==========
strong arrow, breaks A
<----------
weak arrow, breaks B
The semantics of arrow does not depend on type of sketch\branch.
In particular, strong arrows can be used to show loop breaks,
and weak arrows can be used to show loop continues.
examples
D
E
F
G
H
<======
strong arrow, breaks G
<------
weak arrow, breaks H, i.e. continues G
<--------------
weak arrow, breaks E, i.e. continues D
<==============
strong arrow, breaks D
<==========
strong arrow, breaks F
<------
weak arrow, breaks E, i.e. continues D
In addition, the occurrence of an arrow may serve as the end-mark
of the static skip-scope for condition(s) (see "conditions").
branching
Simple sketches with several branches are used to represent
branchings, such as switch/case, try/catch fork/join etc.
Corresponding mappings are defined separately for every
base language.
Java
comments
Comments are semantically insignificant except the scheme comment
starting with two slashes:
//
any scheme, which comment is prefixed by "//" is a block comment,
and will be skipped at textualization.
block
In general, a Java block is represented as a simple branch.
At textualization, the branch body will be enclosed into braces, e.g.
String businessday[ ] =
"Monday", "Tuesday", "Wednesday", Thursday", "Friday"
;
class
Any Java-class is mapped as a module sketch with head.
Its body contains one branch, representing the class body (block).
The part of class declaration, preceding the class body
is located in the module head(s).
method
A method is mapped as a module sketch with head.
Its body contains one branch, representing the method body (block).
The part of method declaration, preceeding the class body
is located in the module head(s).
Control flow regulations inside methods accord with common
principles. Some special branching features are given below
(sections "try/catch" and "switch/case").
The return statement is expressed as a strong arrow breaking
(reaching) the method module skecth. The arrow text contains the
return-expression.
try/catch
A try-catch statement is mapped as a simple sketch with an empty
head of specific type (!!). The first branch corresponds to the body
of the try-clause, the following branches correspond to the catch-
clauses. The first (try-)branch is headless, while others have
catch-paramaters written in the branch head of specific type (!).
example
From: J. Bishop. Java Gently. Addison-Wesley, 1997. 332-334
import javagently.Text;
import java.io.*;
class binary
class binary
Javadoc
The animated binary search program
@author J.M.Bishop
BinarySearch
static int BinarySearch(item a[ ], item x, int left, int right)
throws ItemNotFoundException
display(a, left, right);
search
<==============left
throw new ItemNotFoundException();
int mid = (int) ((left + right) / 2);
? x.equals(a[mid])
<==========mid
<==============BinarySearch(a, x, left, mid);
<==============BinarySearch(a, x, mid+1, right);
main
public static void main(Srting[ ] args)
throws IOException
DatainputStream in = new DataInputStream(System.in);
System.out.println("**** Testing the binarysearch ****");
System.out.println("Type in 10 characters separated by spaces");
fill a[ ]
* (int i=0; i
a[i] = new item(Text.readChar(in));
loop to try several searches
try (next value)
!!
counter = 0;
Text.prompt("Find what value?");
item x = new Item(Text.readChar(in));
System.out.println("The array is:");
System.out.println("0 1 2 3 4 5 6 7 8 9");
try (search for the value)
!!
int found = BinarySearch(a, x, 0, a.length-1);
do whatever is necessary with a[found]
System.out.println((char) x.data +
" was found at position " + found +
" in " + counter + " probes.");
catch
! (ItemNotFoundException e)
react to x not being there
System.out.println((char) x.data +
" was not found in " + counter + " probes.");
catch
! (EOFException e)
<==========
break
* static
item a[ ] = new item[10];
int counter;
display
static void display(item[] a, int left, int right)
* int j = 0; j < left; j++
* int j = left; j <= right; j++
System.out.print((char) a[j].data + " ");
System.out.println( );
counter++;
class ItemNotFoundException
class ItemNotFoundException extends Exception
class item
class item
item
item(char i)
equals
boolean equals(item x)
<======data == x.data;
less
boolean less(item x)
<======data < x.data;
int data;
switch/case
A switch/case statement is mapped as a simple sketch with head of
specific type (??). The sketch head contains the switch-expression.
The branches correspond to the case-clauses. The switch label
(case-expression) is written in the branch head of specific type (?).
example
?? month
? 4:
? 6:
? 9:
? 11:
<======
? 2:
? isLeap(year)
days = 29;
<======
<======
? :
default
member grouping
Member grouping is an additional tool for structuring sketchy
Java texts. Such groupings are semantically insignificant.
group
An arbitrary group of sequential branch members may be formed
by enclosing them into a headless module sketch.
A group can be easily named (by inserting the name as module
comment), iconified and surpressed to block comment (by
inserting two slashes at the start of its comment).
At textualization, block comments are skipped, other groups
are simply opened. It is assumed that there are no arrows
breaking (reaching) group (or its branch).
prefixed group
An arbitrary group of sequential branch members may be formed
by enclosing them into a module sketch with head of type "*".
Such member group is called the prefixed group. At textualization
(if it is not a block comment), it is opened, but the head text
is inserted in front of every simple primitive member of the branch.
For example, instead of the group
public integer constants for size
public static final int SIZE_DEFAULT = 0;
public static final int SIZE_FULL = 1;
public static final int SIZE_LONG = 2;
public static final int SIZE_MEDIUM = 3;
public static final int SIZE_SHORT = 4;
the following prefixed group may be used
* public static final int SIZE_
DEFAULT = 0;
FULL = 1;
LONG = 2;
MEDIUM = 3;
SHORT = 4;