1. General information1.1. Rapier is a high-level interactive language intended for teaching programming and solving small applied problems on a computer. The language is primarily aimed at middle-aged and older schoolchildren (11-17 years old), but can be used by other categories of users.
1.2. Rapier, along with Robik, is the input language of the Schoolgirl programming system. As with the Robik language, nadprogrammed operations in Rapier are performed by non-language system tools.
1.3. The first version of the Rapier was developed in 1978-1979 and was used in school work with schoolchildren and students. During the development of the "Schoolgirl" system, the language was completely redesigned.
1.4. Rapier is a concentric family of languages with a consistently expandable set of features. Each concentr can be considered as a closed language-shell.
This document provides a brief description of the main features of the external concentration of the canonical (school) version of the Rapier.
1.5. Russian is chosen as the base ethnic language for the Rapier. In the process of implementing the language on the instrumental computer, an English version was also developed. Work is underway on the Estonian and Georgian versions. It is possible to create versions based on other languages.
2. Vocabulary and general program structure2.1. The lexical structure of the Rapier is almost the same as Robik’s vocabulary, described in document 3533847.00058-01¤35-02. In Rapier, the same lexical units are distinguished: whole and fractional numbers, texts, words, special characters. The form of these tokens is traditional. The main differences between the Rapier and Robik are as follows:
1. It is allowed to write fractional numbers in an exponential form, for example, 156.65E12 means 156.65x1012.
2. Unary + and - are not considered as components of the lexeme, but as operations.
3. In Rapier, there are several times more special characters, including compound ones, than in Robik.
2.2. The general structure of the program and the order of execution of individual regulations on Robik and Rapier have much in common. A Rapier Program is a sequence of directives, procedural blocks, and name descriptions. The procedure for working with directives and procedural blocks is the same as in Robik.
2.3. Unlike Robik, arbitrary arrangement of prescriptions by lines is allowed (you can write several prescriptions on one line and distribute one prescription on several lines). Spaces and line breaks can be used anywhere in the program, but not inside lexemes (syntactically significant spaces can be used inside texts). Between two tokens that are not context sensitive, at least one space or newline is required.
The comment in Rapier is in special brackets. The comment is syntactically equivalent to a space and can be inserted between any two lexemes.
3. Names and expressions3.1. Rapier is a partly typed language. Each name used in a program or procedure block can be described with an indication of the type. A name type defines the kinds of values that can be assigned to that name. If the name is not described or described without specifying a type, it defaults to a universal type. Such a name can be assigned values of any kind.
In the online version of the Rapier, the description of the names is used as a debugging tool. It is assumed that in the batch version the descriptions should be mandatory.
The scope of the descriptions covers the main program, the procedural block in which the name is described, and all the procedures and functions called from it that do not describe the local names and formal parameters that coincide with it in writing. Thus, the descriptions simultaneously determine the localization of names.
Name descriptions and type indications in Rapier are not required, therefore, for the quick solution of small tasks, it can be used as a typeless language.
3.2. In Rapier, the following types of name values are distinguished:
- whole numbers
- fractional numbers
- texts
- sets
- tuples
- procedures
- functions
- files
- modules
- drawings
- frames
- tables
- empty value
3.3. All names other than standard, which have not been assigned values in this program, have an empty value. The system provides a protected standard name NULL, which is always null.
3.4. Over any pairs of names in Rapier, a TYPE comparison operation is defined, the result of which is TRUE if the declared types of names are the same and FALSE otherwise.
Over any pairs of values (expressions), the operation of comparing the TYPE is defined, the result of which is TRUE, if the types of values of these expressions are the same.
3.5. The following operations are defined above the numbers in Rapier:
unary arithmetic: + and -;
binary arithmetic: +, -, *, /, // (division completely), ** (exponentiation);
comparison operations: =, / =, <=,> =, <,>
All operations have the usual mathematical meaning; it is allowed to compare integers and fractional numbers for equality: the condition 35 = 35.0 is considered true.
3.6. The following operations are defined above the texts:
+ - concatenation (merging of texts), for example,
"Led" + "ipon" = "bicycle" ;
FROM - check whether the character belongs to the text, for example,
"M" OF "microscope" is true ;
[] - sampling (taking a character from the text by index), for example,
“Bicycle” [5] = “s” ;
[:] - clipping (selection of text on the initial and final indices), for example,
“Crocodile” [2: 4] = “rock” ;
# - power (unary operation that determines the number of characters in the text), for example,
# "Airplane" = 7 .
=, / = - text comparison.
In the operations of cutting and sampling, any expressions can be used as indices, the values of which are natural numbers not exceeding the power of the corresponding text. The left index in the clipping should not exceed the right.
These two operations can occur both on the left and on the right of the assignment mark, allowing in the latter case text editing. The length of the text when editing cannot be changed: the substituted text must have the same length as the replaced area. For example, after assignments:
"Crocodile" -> Beast; “Osh” -> Beast [2: 3];the name Beast will receive the value "cat". Assignments
“Kosh” -> Beast [2: 3]; “A” -> Beast [2: 3];are unacceptable because of the discrepancy between the lengths of the replacement and the replaced parts of the text.
3.7. Composite data structures in the interactive version of the Rapier are represented by sets, records and tuples. Each of these structures can contain an arbitrary number of elements. The structure element can be any language object, regardless of its type.
In the batch version, typed versions of these constructions are allowed: all elements of sets and tuples must be of the same type, and in the records each element must be of a certain type.
A set is considered as an unordered collection of pairwise different elements. Access to a single element of the set is not possible. Only the verification of the belonging of an element to a set, operations on the whole set and the sequential search of its elements using a special form of the cycle are allowed.
A record is treated as an unordered collection of named fields. Access to the entry element is possible only through the field name.
A tuple is considered as an ordered collection of arbitrary elements. Access to a tuple item is possible by index.
This operation allows you to build a new structure from an arbitrary number of elements represented by the values of expressions. For the formation of the desired structure, it is necessary to list all expressions separated by commas, the values of which should become elements of the structure, and enclose them in special brackets, the shape of which is determined by the type of structure. Simple angle brackets <> define the formation of a tuple, curly brackets {} or (* *) - the formation of a set, special brackets <$ $> - the formation of a record. In addition, when creating a record, before each element the field name must be indicated, separated from the elements by a colon.
For example, the expression <2, “search”, 5.3, A> defines the formation of a tuple of four elements: the number 2, the text “search”, the number 5.3 and the meaning of the name A. The expression {2, “word”, 2, 2} defines the formation sets of two elements: the number 2 and the text "word". The expression <$ First Name: “Sergey”, Last Name: “Ivanov”, Year of Birth: 1950 $> defines the formation of a record of three fields: Name, Last Name and Year of birth.
3.9. For all structures, the following operations are defined:
FROM - check accessory;
# - determination of power (number of elements);
= and / = - comparison for equality and inequality.
It should be noted that two entries with different field structures are considered to belong to different types.
Two sets are considered equal if they consist of the same elements, regardless of the order in which they are written, for example,
(* 1, 5, 5, <1, 2>, 1, *) = (* 5, <1, 2>, 1, *)
Two tuples are considered equal if they consist of the same elements arranged in the same order, for example:
<1, 5, <1, 2 "= <1, 2 + 3, <1, 1 + 1"
<1,2,3> / = <3,2,1>
Two records with the same field structure are considered equal if the fields of the same name have the same values, for example:
<$ First Name: “Sergey”, Last Name: “Ivanov” $> =
<$ Last name: "Ivanov", First Name: "Sergey" $>
<$ Number: 5, Speed: $ 10> / = <$ Type: 5, Height: $ 10>
3.10. In addition to the operations listed in paragraphs 3.4, 3.6 and 3.9, over the sets are defined the operations of union (+), intersection (*) and difference (-), having the usual mathematical meaning.
Similarly, the same operations are defined on tuples as on texts, and multiple indexing is allowed for nested tuples; the expressions A [2] [3] and A [2, 3] are semantically equivalent and define the third element of the tuple, which is the second element of the tuple A.
Above the records, except for general operations, only the selection of the element by the field name is defined. For example, the expression X. Address defines the values of the Address field in an entry that is the value of the name X.
As with tuples, sampling can be used on both sides of the assignment mark. For nested records, multiple sampling is defined, for example: X. Address. Apartment.
3.11. Above the procedures and functions, as for the values of the names, in addition to the general operations listed in section 5.3.4, the call operation is defined, the syntax of which is described by diagram 5.
3.12. For other types of operation values in Rapier are not defined. Actions on such values are carried out using special instructions or procedures.
Information on working with files and modules in Rapier is given in section 7. Working with drawings and frames is carried out using the “Sword” graphic system, which is part of the “Schoolgirl” system. Tables as a kind of values are provided only for the extraversion version of Rapier and will not be considered here. The semantics of the empty value is the same as in the Robik language.
3.13. In Rapier, as in Robike, the protection of names is provided. Partial or full protection can be set and removed by the user using the appropriate types of ENABLE and DISABLE prescriptions, the syntax of which is described in diagram 6. Some names, for example, the names of procedures and functions during their execution and the name of the loop variable within the body of this loop, have absolute protection which cannot be charged by means accessible to the user.
3.14. The syntax of an expression in Rapier is described by diagram 7. As follows from the diagram, an expression is a sequence of binary operations of constants, formers, simple names and expressions in brackets connected by signs, each of which can have one or several unary operations, and then an arbitrary sequence operations of sampling, cutting and calling.
Thus, the structure of the expression as a whole is traditional for high-level languages.
3.15. The following operational priorities have been adopted in Rapier:
1. Expressions in brackets and component expressions in formers;
2. Formation of structures;
3. Calculation of the actual parameters of functions and index expressions;
4. Samples, clippings, function calls;
5. Unary operations;
6. Exponentiation;
7. Operations *, /, // (multiplication, intersection, division, division completely);
8. Binary + and - (addition, concatenation, union, set difference).
The described procedure is generally consistent with that adopted in mathematics, with the exception that intersection of sets (*) received a higher priority in Rapier than union (+).
3.16. The syntax of a condition in Rapier is described in diagram 8. The term “condition” corresponds to the term “logical expression” used in other languages. In Rapier, logical values cannot be assigned to names; therefore, logical expressions are allowed only in certain contexts, for example, in the BYE cycle and in branch instructions.
This selection of logical expressions is introduced into the language from methodological considerations in order to emphasize their semantic differences from expressions of other types.
Comparison operations and logical connectives used in conditions have traditional semantics.
Priorities of operations in the following conditions:
1. Conditions in brackets and expressions included in the terms;
2. Comparison operations and ownership checks;
3. NOT;
4. And;
5. OR.
4. Assignment, input and output4.1. The syntax of the assignment, input and output prescriptions in the Rapier language is described in diagrams 9-11. The semantics of these prescriptions hardly differs from the semantics of similar prescriptions in the Robik language. Therefore, only the main differences between the specified prescriptions in these languages are listed here.
4.2. When comparing the syntax of prescriptions, it is necessary to take into account that, despite the external similarity, the structure of expressions in Rapier is much richer than in Robik, therefore prescriptions for assignment and output in Rapier allow performing various operations on data of various kinds, which in Robik can only be done using specialized performers .
4.3. Prescription of the output in Rapier allows you to display not only simple (numbers, texts), but also composite values (sets, tuples, records). The output form is the same as the type of the corresponding formers in the language. Similarly, in the data entry mode, composite values can be entered.
When outputting texts and entering them in TEXT INPUT mode, bordering quotes are not indicated. Texts entered as part of the structure and entered in the DATA ENTRY mode are surrounded by quotes.
If the input mode is not specified, the default is TEXT INPUT.
4.4. The output of any values can be made with an indication of the format: after the output expression, the number of positions taken after the colon is indicated. For fractional numbers, it is possible to specify a double format: the number of characters in the fractional part of the number is also indicated. If the value does not fit in the allotted number of positions, then it is displayed in free format.
4.5. In accordance with the concentric structure of the Rapier, input and output switching to other devices can be performed in various ways. Along with a one-time switch, performed in the same way as in Robik, by specifying the desired mode in the prescription header (for example: PICTURE OUT: A, B;), in Rapier it is possible to switch all output or input information to one or more devices or files . To do this, apply the appropriate form of regulations ON and OFF.
For example: Turn ON PAPER OUTPUT;
5. Control structures Rapier5.1. The control structures of the Rapier include three types of branching: IF, SELECT-FROM, four types of cycle: BYE, REPEAT, FOR-FROM and FOR-FROM, means for describing and calling functions and procedures, and the EXIT clause for exiting the procedures.
This section discusses the requirements of branching and looping, and work with procedures and functions is discussed in the next paragraph.
The syntax of the listed constructions is described in diagrams 5, 12-15. As can be seen in the diagrams, all these prescriptions have a frame structure, which makes it possible to indicate in the loop body and branch alternatives an arbitrary number of prescriptions without using artificial means for their combination.
5.2. The semantics of simple branching (conditional prescription) IF-TO-OTHER is quite traditional.
Example:
IF A TO
5 -> A; CONCLUSION: In;
ANYWAY
5 -> B; CONCLUSION: A;
EVERYTHING;
5.3. As can be seen in Diagram 12, the multi-branch prescription (SEL-FR) consists of an arbitrary number of alternatives, each of which is represented by a condition followed by one or more prescriptions, separated by a semicolon. The condition is separated from the prescriptions by a colon, alternatives are separated by the | character. In the end there may be a design ANY.
The prescription is executed as follows. Sequentially, in the order of recording alternatives, the conditions specified in them are checked. If one of them turned out to be true, the prescriptions from the corresponding colon to the nearest alternative separator (|), the words AKHA or ALL, are executed. After that, the execution of the prescription ends. If none of the conditions were true, the prescriptions between AKA and ALL (if the word AKIA is used) are fulfilled. Thus, in any case, no more than one of the provided alternatives is performed.
Example:
SELECT FROM
Wind <= 3: CONCLUSION: “weak” |
Wind <= 7: CONCLUSION: "moderate" |
Wind <= 70: CONCLUSION: “Alarm!”
NECESSARY CONCLUSION: “The speed is incorrectly set”
EVERYTHING;
5.4. The second type of prescription SELECT is executed in the same order, but the condition being checked is of the form: b0 = ba, where
b0 - the value of the switching expression written between the words SELECT and FROM,
ba is an expression written in the alternative (before the colon). There may be several such expressions (separated by commas).
The value of the switching expression is calculated once at the beginning of the execution of the prescription. Otherwise, the semantics of this prescription corresponds to clause 5.3.
Example:
SELECTION FROM FROM
5: CONCLUSION: “Excellent” |
4: CONCLUSION: “good” |
3: CONCLUSION: “medium” |
1.2: CONCLUSION: “bad” |
ELSE CONCLUSION: “Error”
EVERYTHING;
5.5. The BYE cycle (diagram 13) has the traditional semantics: first, the condition specified in the cycle header is checked. If it is true, all the prescriptions from the sign :: (read “repeat”) to the word ALL (the body of the cycle) are executed. Then the condition is checked again, etc. If at the next check the condition turned out to be false, the execution of the instruction ends. If it was false at the first check, then the loop body is never executed.
Example:
1 -> X;
UNTIL X <10 :: CONCLUSION: 2 ** X; X + 1-> X ALL;
5.6. The REPEAT loop allows you to perform a certain set of prescriptions a specified number of times. It is performed as follows. First, the value of the expression specified in the loop header is calculated. It must be a non-negative integer, otherwise an error message is displayed. Then the loop body is executed the specified number of times.
Example:
1 -> X;
REPEAT 10 TIMES :: CONCLUSION: 2 ** X; X + 1-> X ALL;
5.7. The FOR-FR cycle corresponds to the traditional progression-type cycle for most languages. The name specified after the word FOR is a cycle variable, the expression after the word OT defines the initial value, the expression after the word TO is the final value, after the word STEP the increment step is indicated. If a step is not specified, it is taken as equal to one. The values of all three expressions must be numbers (integer or fractional). Cycle semantics is traditional. The loop variable in the loop body has absolute protection. After the end of the cycle, it has an empty value.
Example:
FOR X FROM 1 TO 10 :: CONCLUSION: 2 ** X ALL;
5.8. The FOR-FR loop is designed for processing texts and compound structures, as well as files of the corresponding types. When executing this prescription, the loop variable alternately takes the values of each element of the corresponding structure or file (or each character of the text), after which the loop body is executed. As in the FOR-FR loop, the loop variable in the body of this loop has absolute protection, and after its completion it gets an empty value. The expression specified in the cycle header after the word IZ is calculated once before the cycle begins.
Example - counting the number of letters "A" in the text with the name Book:
0 -> Mid;
FOR A Letter FROM A Book :: IF A Letter = “A” THAT MF + 1-> MF ALL ALL;
CONCLUSION: "In the text of the Book", MF, "letters <A>";
6. Procedures and functions6.1. The syntactic structure, as well as the order of description and calling of functions and procedures in Rapier and Robik are very close. Therefore, in this paragraph, only the differences between the procedural apparatus Rapiers and the analogous apparatus of Robik are listed.
6.2. As in Robik, the procedural block in Rapier is the basic unit for localizing names and storing program text. In addition to this, it acquires the properties of the main unit of the description area. As can be seen in diagrams 14-15, when describing formal parameters and local names in Rapier, unlike Robik, one can indicate the type.
6.3. In procedure headers, you can specify the method of passing each of the parameters. In the Rapier, there are three types of parameters that differ in the mode of transmission: input, output and return. These methods are denoted by the symbols =>, <= and <=>, respectively. If the formal parameter is described as input, then the corresponding actual parameter can be any expression. The actual parameters, corresponding to the two other types of formal, can only be names.
Input parameters are passed by value: at the moment of calling the procedure, the value of the actual parameter is calculated and assigned to the corresponding formal, which is then completely protected. For functions in Rapier, as well as for all types of procedural blocks in Robik, this method is the only one possible.
Output parameters are processed as follows. . .
: , — .
6.4. ( ) .
, , . , .
6.5. . . ,
<A, B, C>[X](2, 3);
A, B C, X, 1 3. .
6.6. , , . .
7.7.1. «» , , .
, — , . , , . , , «» : «», .
7.2. , , .
1. , , ( 10-11).
2. ( 6). ( 10-11).
3. , , - ( 13). .
4. ( , , ..) -.
5. «», , , . .
6. , .
7.3. «» . — , — , .
, . , , .
8.8.1. , . , . .
8.2. (). ( 6).
8.3. , . , 15. , .
8.4. — , . , — . , .
8.5. . , . , .
8.6. , , :
1. ;
2. ( );
3. .
8.7. , 8.2-8.4, ,