Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Jackson structured programming
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==A worked example== As an example, here is how a JSP programmer would design and code a [[Run-length encoding|run length encoder]]. A run length encoder is a program whose input is a stream of bytes which can be viewed as occurring in ''runs'', where a run consists of one or more occurrences of bytes of the same value. The output of the program is a stream of byte pairs, where each byte pair is a compressed description of a run. In each pair, the first byte is the value of the repeated byte in a run and the second byte is a number indicating the number of times that that value was repeated in the run. For example, a run of eight occurrences of the letter "A" in the input stream ("AAAAAAAA") would produce "A8" as a byte pair in the output stream. Run length encoders are often used for crudely compressing bitmaps. With JSP, the first step is to describe the data structure(s) of a program's input stream(s). The program has only one input stream, consisting of zero or more ''runs'' of the same byte value. Here is the JSP data structure diagram for the input stream. {{center|[[Image:JSP RLE input.png]]}} The second step is to describe the output data structure, which in this case consists of zero or more iterations of byte pairs. {{center|[[Image:JSP RLE output1.png]]}} The next step is to describe the correspondences between the components of the input and output structures. {{center|[[Image:JSP RLE correspondence.png]]}} The next step is to use the correspondences between the two data structures to create a program structure that is capable of processing the input data structure and producing the output data structure. (Sometimes this isn't possible. See the discussion of ''structure clashes'', below.) {{center|[[Image:JSP RLE program.png]]}} Once the program structure is finished, the programmer creates a list of the computational operations that the program must perform, and the program structure diagram is fleshed out by hanging those operations off of the appropriate structural components. # read a byte # remember byte # set counter to zero # increment counter # output remembered byte # output counter Also, at this stage conditions on iterations (loops) and selections (if-then-else or case statements) are listed and added to the program structure diagram. # while there are more bytes # while there are more bytes and this byte is the same as the run's first byte and the count will still fit in a byte Once the diagram is finished, it can be translated into whatever programming language is being used. Here is a translation into C. <syntaxhighlight lang="c"> #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int c; int first_byte; int count; c = getchar(); /* get first byte */ while (c != EOF) { /* process the first byte in the run */ first_byte = c; count = 1; c = getchar(); /* get next byte */ /* process the succeeding bytes in the run */ while (c != EOF && c == first_byte && count < 255) { /* process one byte of the same value */ count++; c = getchar(); /* get next byte */ } putchar(first_byte); putchar(count); } return EXIT_SUCCESS; } </syntaxhighlight>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Jackson structured programming
(section)
Add topic