Bubble -- Jeffry Johnston, February 2001 Introduction ------------ Something has changed. The bubble sort is no longer content merely with sorting data. This tired algorithm now aims to please by executing programs at ultra-low speeds as well! This is an attempt to turn a standard routine into a programming language as well as get away from the normal program flow. Program Flow ------------ A Bubble program is made up of two parts, a data file (list to be sorted) and a rule file (list of rules). Before the program can be executed the list of rules must be read in and understood. These rules modify how Bubble treats the data. Then, the master loop starts. The interpreter starts at the first piece of data and sees if any rules apply, if so, the commands for those rules are executed. This means it is possible to use every single rule for each piece of data on a pass, although this situation is unlikely in non- trivial programs. One rule that IS always executed is: If this line is greater than the next line then swap this line with the next line. This of course serves as our friendly bubble sort. The other rules are in a section below. If all lines are in the correct sorted order at the end of the instruction cycle, the program terminates. Any lines left over are printed to the default output device. Data file --------- Like an input file to be sorted, the lines of data should be arranged in a list. Each line may be up to 255 characters in length and must be terminated with a CR-LF combination (except the last line). Only the standard ASCII characters (32-126) are valid. The input file makes up the initial memory that the program can use, but it can grow or shrink as needed. Each piece of data is treated as a string rather than a value. When compared, "10" is greater than "1", "10" is less than "2", "A" is less than "a", and "lame " is greater than "lame". Blank lines of course will have the lowest value. Fun data file values -------------------- Air, bath, blow, bobble, burst, chamber, dubble, gum, icious, jet, memory, nebula, pop, scrubbing, soap, sort, tape, warp, wrap, yum. Rule file specifications ------------------------ Key: [] Optional {} Required | Choose one # Number Rule format ----------- The rules and commands have been designed to be written in (mostly) normal english. There are only 2 rules: Note: (text) Specifies a comment block and is simply skipped over. It doesn't need quotation marks. Start the comment on its own line and end it with a blank line. If (line) is (comparison) {(line)|(text)} then (command)[and (command).| , (command), [, (command)], and (command)]. On each line all the if statements are tested and executed if true. Concerning numbers ------------------ When a line of data contains only numbers, mathematical operations can be performed on it. All numbers are long integers, and can range from -2,147,483,648 to 2,147,483,647. Anything outside that range will not be considered a number. Even when a piece of data is a considered a number, comparison and string operations will treat it like a string. Line choices ------------ When referring to a line, use one of these phrases: the {top|first} line the {bottom|last} line line (#) this line the {line (#) below this line|next line} the {line (#) above this line|previous line} a randomly chosen line Remember that each data line is examined by each rule, hopefully that will help to understand choices such as "this line". If one of these line specs causes the interpreter to go outside the current data boundaries, the command will either be ignored or a new line will be created, depending on the nature of the command. Comparison operators -------------------- When testing for equality, use one of these phrases: the same as Phrase is not needed with the line choice "text". less than greater than {either less than or the same as|either the same or less than} {either greater than or the same as|either the same or greater than} different than Text format ----------- Surround text with a pair of either single (') or double (") quotation marks. Commands -------- Here is the list of commands that can be used with the "if" rule, most are pretty self-explanatory: remove {(line)|all lines} put a line {above|below} (line) that contains {(text)|a randomly chosen number} move (line) {above|below} (line) copy (line) and {put it {above|below} (line)|replace (line)} swap (line) with (line) change (line) to (text) split (line) after letter (#) Creates a second line under the first for the split off part. overwrite (line) starting from {the beginning|the end|letter (#)} with (#) letter[s] of (line) get a line from the user and {put it {above|below} (line)|replace (line)} Inputs a line from the keyboard or default input device. display {(line)|the text (text)} Outputs something to the screen or default display device. Does not output a carriage return. perform a carriage return Outputs a carriage return. add {(#)|(line)} to (line) If the line does not contain a number then no action is taken. subtract {(#)|(line)} from (line) If the line does not contain a number then no action is taken. multiply (line) by {(#)|(line)} If the line does not contain a number then no action is taken. divide (line) by {(#)|(line)} If the line does not contain a number then no action is taken. reverse the sort order Reverses the sorting rules specified in the above section "Data File". sort (text) like it is (comparison) (text) This can make some awkward situations easier to handle by forcing a specific sort order. Any data line that starts with (text) will fall under this command. Example Programs ---------------- Bubble Sort ----------- Program - - - - If this line is greater than the next line then swap this line with the next line. Input File - - - - - - (any lines you want to be sorted) Hello World ----------- Program - - - - (null) Input File - - - - - - Hello World Echo ---- Program - - - - If this line is different than line 2 then get a line from the user and replace line 1, display line 1, and perform a carriage return. Input File - - - - - - a + Unfortunately, I am not very good at actually writing programs in this language to show off its "powers", but I'm hoping to learn how someday :) I decided to put out this spec even though I haven't yet finished an interpreter or better example programs because it's been sitting around for a while. Contact me ---------- bubble@kidsquid.com http://kidsquid.com/