SAIL (programming language): Difference between revisions

Content deleted Content added
Description: example
Line 11:
 
==Description==
===Basic structure and statements===
Like many ALGOL systems, and the later [[Pascal (programming language)|Pascal]], the basic structure of SAIL is based on the ''block'', which is denoted by the code between the keywords {{code|BEGIN}} and {{code|END}}. Within a block there is further structure, with the ''declarations'' of local variables at the top, if any, and the code, or ''statements'', following. In contrast to most dialects, SAIL allowed one to place a string after the {{code|BEGIN}}, like {{code|BEGIN "program"}}, and then end the block with {{code|END "program"}}. The compiler would use these, if entered, to check for proper bracketing.{{sfn|Smith|1976|p=13}}
 
Standard statements included {{code|IF...THEN...ELSE}},{{sfn|Smith|1976|p=11}} {{code|FOR...STEP...UNTIL...DO}},{{sfn|Smith|1976|p=15}} {{code|WHILE...DO}} for top-tested loops, {{code|WHILE...UNTIL}} for bottom-tested, and {{code|GOTO}} which used a label.{{sfn|Smith|1976|p=17}} A curious statement wasThe {{code|CASE}}, whichwas tooksimilar anto integer{{code|switch}} valuein andC, thenbut rannormally oneused ofa thesomewhat followingdifferent statementssyntax, like {{code|CASE i OF ("Zero","One","Two");}}, which returns the appropriate string based on the value of i.{{sfn|Smith|1976|p=11}} {{code|DONE}}If exitedone fromwanted ato block,test typicallyexplicit usedvalues in loops, and {{code|CONTINUE}} returned to the top ofCASE, the block.values Anhad infiniteto loopbe wasin typicallysquare implemented with {{code|WHILE TRUE DO...}}.{{sfn|Smith|1976|p=18}}brackets:
The basic variable types in SAIL are [[Integer (computer science)|integers]], [[Floating-point arithmetic|reals]] (floating point), [[Boolean data type|booleans]], and [[String (computer science)|strings]].{{sfn|Smith|1976|p=2}} Any of these types can be turned into an array by adding the {{code|ARRAY}} qualifier and placing the array bounds in brackets, for instance, {{code|REAL ARRAY weeks[1:52]);}}. SAIL supported 1-d and 2-d arrays.{{sfn|Smith|1976|p=4}} Type conversions were automatic, so {{code|INTEGER i;i←SQRT(5);}} would convert the value 5 to a double as that is what SQRT requires.{{sfn|Smith|1976|p=13}}
 
<code>
Standard statements included {{code|IF...THEN...ELSE}},{{sfn|Smith|1976|p=11}} {{code|FOR...STEP...UNTIL...DO}},{{sfn|Smith|1976|p=15}} {{code|WHILE...DO}} for top-tested loops, {{code|WHILE...UNTIL}} for bottom-tested, and {{code|GOTO}} which used a label.{{sfn|Smith|1976|p=17}} A curious statement was {{code|CASE}}, which took an integer value and then ran one of the following statements, like {{code|CASE i OF ("Zero","One","Two");}}, which returns the appropriate string based on the value of i.{{sfn|Smith|1976|p=11}} {{code|DONE}} exited from a block, typically used in loops, and {{code|CONTINUE}} returned to the top of the block. An infinite loop was typically implemented with {{code|WHILE TRUE DO...}}.{{sfn|Smith|1976|p=18}}
CASE I OF
BEGIN
[0] 10;
[4] 25;
[6][7] 50
END;
</code>
 
This code will ignore values like 1 to 3, and only return a value for the listed values. Note that the last item cannot have a semicolon following.{{sfn|Smith|1976|p=19}}
 
{{code|DONE}} exited from a block, typically used in loops, and {{code|CONTINUE}} returned to the top of the block. An infinite loop was typically implemented with {{code|WHILE TRUE DO...}}.{{sfn|Smith|1976|p=18}}
 
Procedures were implemented in a fashion similar to the [[C programming language]], with the return type, if any, in front of the name, for instance, {{code|STRING PROCEDURE toUpper(STRING originalStr);BEGIN...}}. Note the uncommon use of the semicolon here, whereas PASCAL would immediately follow with a block, typically a {{code|BEGIN}}. In order to improve performance, SAIL added two qualifiers, {{code|SIMPLE}} and {{code|RECURSIVE}}. If a procedure did not specifically say {{code|RECURSIVE}}, when the procedure was called it would not create an [[activation record]], thereby improving performance. SAIL also included the {{code|FORWARD}} qualifier, used to insert [[forward declaration]]s, typically when two procedures call each other.{{sfn|Smith|1976|p=21}} {{code|RETURN}} worked as in C, both exiting the procedure and returning to the caller, as well as returning a value if the procedure uses one.{{sfn|Smith|1976|p=23}} Parameters passed to the procedures could be by {{code|VALUE}} or {{code|REFERENCE}}, the later allowing values to be passed back.{{sfn|Smith|1976|p=24}}
Line 21 ⟶ 33:
As a systems programming language, performance was important and to help with this, SAIL included a {{code|DEFINE}} which used string-replacement in a fashion similar to C's {{code|#define}} macros.{{sfn|Smith|1976|p=25}} A difference was that the delimiters around the substitution had to be defined, for instance {{code|REQUIRE "[][]" DELIMITERS;DEFINE maxSize{{=}}[100];}}. One common use of these macros was to define character constants like {{code|CRLF}}, as these were not part of the basic language.{{sfn|Smith|1976|p=25}} Another was to redefine the {{code|COMMENT}} statement to the shorter {{code|!}}.{{sfn|Smith|1976|p=26}}
 
 
The language used the left-arrow for assignment, or the underscore on platforms that did not have [[Stanford ASCII]].{{sfn|Smith|1976|p=5}} It included a number of standard functions like [[square root]], all of the common math operators, and was otherwise similar to most ALGOL derivatives for normal programming.{{sfn|Smith|1976|p=6}}
===Data types and operators===
The basic variable types in SAIL are [[Integer (computer science)|integers]], [[Floating-point arithmetic|reals]] (floating point), [[Boolean data type|booleans]], and [[String (computer science)|strings]].{{sfn|Smith|1976|p=2}} Type conversions were automatic, so {{code|INTEGER i;i←SQRT(5);}} would convert the value 5 to a double as that is what SQRT requires.{{sfn|Smith|1976|p=13}} Any of these types can be turned into an array by adding the {{code|ARRAY}} qualifier and placing the array bounds in brackets, for instance, {{code|REAL ARRAY weeks[1:52]);}}. SAIL supported 1-d and 2-d arrays.{{sfn|Smith|1976|p=4}} Type conversions were automatic, so {{code|INTEGER i;i←SQRT(5);}} would convert the value 5 to a double as that is what SQRT requires.{{sfn|Smith|1976|p=13}}
 
The language used the left-arrow for assignment, or the underscore on platforms that did not have [[Stanford ASCII]].{{sfn|Smith|1976|p=5}} It included a number of standard functions like [[square root]], all of the common math operators, and was otherwise similar to most ALGOL derivatives for normal programming.{{sfn|Smith|1976|p=6}}
 
Strings were manipulated using [[array slicing]], with {{code|aStr[i TO j]}} returning the substring with characters from i to j, or {{code|aStr[i FOR j]}} which returned the substring starting at i and running for j characters.{{sfn|Smith|1976|p=12}} The {{code|INF}}(inity) keyword represented the end of the string, so one could {{code|aStr[i TO INF]}} to return everything from i on.{{sfn|Smith|1976|p=13}} String functions and operators included {{code|EQU}} for testing if two strings were equal,{{sfn|Smith|1976|p=11}}, the ampersand for concatenation, {{code|LENGTH}} and {{code|LOP}} which removes the first character from the string.{{sfn|Smith|1976|p=12}}
 
==Example==
The following code, found in the Tutorial, converts an input string to upper case.{{sfn|Smith|1976|p=21}}
 
<code>
STRING PROCEDURE upper(STRING rawstring);
BEGIN "upper"
STRING tmp;
INTEGER char;
tmp←NULL;
WHILE LENGTH(rawstring) DO
BEGIN
char←LOP(rawstring); COMMENT LOP returns the first character and moves the pointer past it
tmp←tmp&(IF "a" LEQ char LEQ "z" THEN char-'40 ELSE char);
END;
RETURN(tmp);
END "upper";
</code>
 
==Uses==