You get a bonus - 1 coin for daily activity. Now you have 1 coin

ALGORITHMIC COMPILATOR FORTRAN

Lecture



Fortran is the earliest high-level language. It is used for mathematical tasks and scientific research and is highly platform independent. A huge number of application libraries have been accumulated in FORTRAN, which allows to quickly and efficiently carry out any scientific research.
Here are the components of the Fortran language as applied to the MS-Fortran version.

Content:

  1. MS-Fortran Metacommands
  2. Programs and compiled parts of programs
  3. Input / Output in Fortran
  4. FORTRAN Operators
  5. Fortran Expressions
  6. Fortran Names
  7. Types in Fortran
  8. Strings in FORTRAN
  9. Symbols in FORTRAN

MS-Fortran Metacommands

Meta-language is the MS-Fortran compiler control language. Meta-commands allow you to define options that affect all compilation operations. For example, with the help of meta-commands, you can turn on or off the generation of a listing file, check the code for an account error, or use Fortran features that are not part of a subset or the full standard of the language. The metalanguage contains commands that are inserted into the source file, each of which occupies a separate line, and each of which begins with the dollar symbol ($) in the first column.

Meta-language is a language level that allows you to expand the use of the MS-Fortran compiler. Although most implementations of Fortran have compiler controls, the MS-Fortran metacommands are not part of the Fortran standard (and therefore not mobile).

Below are the current meta-commands:

  $ [NO] DEBUG $ [NO] LARGE $ PAGESIDE
   $ DEVFNH $ LINESIDE $ STORAGE
   $ DO66 $ [NOT] LIST $ [NOT] STRICT
   $ [NO] FLOATCALLS $ MESSADE $ SUBTITLE
   $ INCLUDE $ PAGE $ TITLE 

Programs and compiled parts of programs

The MS-Fortran compiler produces program units. They can be the main program, subroutine or function. You can compile any of these units separately and then load them together without combining them before compiling.

1.Program.

Any software unit that does not begin with a FUNCTION or SUBROUTINE statement. The first operator may be PROGRAM, but such an operator is optional. Program execution always starts with the first statement executed in the main program. Consequently, each executed program should have a single main program.

2. Subroutine.

A program unit that can be called from other program units by the CALL operator, when called, the subroutine performs a set of actions defined by its executable statements, and then returns control to the agent immediately following the call operator. The subroutine does not directly return values, although they can be passed to the calling program unit through parameters or common variables.

3. Function.

A programming unit that can be used in an expression. The function directly returns the value that is used when calculating this expression, and in addition can return values ​​via parameters. There are three types of functions: external, internal and function-operator. (The function operator cannot be compiled separately).

4. Subroutine data block.

A software unit that provides the initial values ​​of variables in COMMON blocks. Variables are usually set by the DATA operator, but variables in COMMON cannot be entered anywhere except in a data block subroutine.

Subroutines and functions allow you to create large structured programs that can be divided into parts. This gives advantages in the following situations:

  1. If the program is large, splitting it apart makes it easy to create, test, and build it.
  2. If the program is large and recompiles the entire source code takes a long time, splitting it into parts saves compile time.
  3. If you need to use some procedures in many other programs, you can create one object file from these procedures and then load it into each of the programs that need these procedures. This will be your user subroutine library.
  4. If the procedure must be used in different cases in different ways, you can write it into a separate file and compile separately. Then, to ensure its variability, you can change the content and even rewrite the names of the Assembler or MS Pascal, and the rest of your program will not change.

Input / Output s Fortrana

Input is the transfer of data from the external environment or from the internal file to the internal memory. The transfer process is called reading. The output is the transfer of data from internal memory to the external environment or to an internal file. This process is called writing.

In Fortran there is a set of operators providing such data transfer, in addition there is a set of operators for editing such data.

In addition to data transfer operators, there are several auxiliary I / O statements that control the external environment, or define or describe the properties of the connection to the external environment.

Table 1-1 lists the I / O operators that perform each of these three functions.

  --------------------------- T ---------------------- ----- ¬
   | Input / Output Functions |  I / O Operators |
   + -------------------------- + ---------------------- ----- +
   |  Data transfer |  READ |
   |  |  WRITE |
   |  |  |
   |  Auxiliary functions |  OPEN |
   |  input / output |  CLOSE |
   |  |  BACKSPASE |
   |  |  ENDFILE |
   |  |  REWIND |
   |  |  INQUIRE |
   |  |  LOCKING |
   |  |  |
   |  Positioning |  BACKSPASE |
   |  in file |  ENDFILE |
   |  |  REWIND |
   L -------------------------- + ---------------------- ------
           Tab.  1-1 I / O statements.

The following points are also needed to understand the I / O system:

1. Records.

The concept on which the Fortran file system is based. A record is a sequence of characters or values. There are three types of entries: formatted, formatless, and end of file.

2. Files.

Record sequences. Files can be external or internal.

External files are files related to the device or the device itself. The internal file is a text variable, which is used either as text or as the assignment of some formatting input / output actions.

All files have the following attributes:
a. file name (arbitrary)
b. file position indicator
c. structure (format, non-format, or binary)
d. access method (sequential or direct)

Although a wide variety of file types is possible, most applications come down to two types: implicitly open and explicitly open, external, sequential, formatted files. See part 3 "Operators" for descriptions of I / O operators. For a complete description of the records, files, and editing format information, see part 4, I / O System.

FORTRAN Operators

Operators are a set of functions such as calculations, writing the results of calculations, changing control chains, reading and writing files, and defining information for the compiler. Fortran operators are divided into two main classes: executable and non-executable.

Executable statements cause the required actions. Outstanding operators do not cause any action. Instead, they define, describe, or classify program elements, such as input points, data, or program units. Table 1-2 describes the functional categories of operators.

  -------------------- T ----------------------------- ------- ¬
 |  Category |  Description |
 + ------------------- + ----------------------------- ------- +
 |  Assignment |  Executable  Assigns the value |
 |  |  variable or array element.  |
 |  |  |
 |  Comment |  Non-executable.  Allows comments- |
 |  |  inside the subroutine.  |
 |  |  |
 |  Management |  Executable  Manages the order you- |
 |  |  complete operators.  |
 |  |  |
 |  DATA |  Non-executable.  Assigns initial- |
 |  |  values ​​of variables.  |
 |  |  |
 |  FORMAT |  Non-executable.  Provides information |
 |  |  edit data.  |
 |  |  |
 |  Input / Output |  Executable  Defines the texts and |
 |  |  data transfer addresses and other special- |
 |  |  input / output features.  |
 |  |  |
 |  Description |  Non-executable.  Defines the attributes |
 |  |  variables, arrays, and function names |
 |  |  programmer.  |
 |  |  |
 |  Operator Function |  Non-executable.  Defines a simple, |
 |  |  locally used function.  |
 |  |  |
 |  |  |
 |  Headline |  Non-executable.  Defines the beginning |
 |  software |  programming unit and describes it |
 |  units |  formal parameters.  |
 |  |  |
 L ------------------- + ----------------------------- --------
       Tab.  1-2 Categories of Fortran operators. 

For full information on using MS-Fortan operators, see part 3 "Operators".

Expressions s FORTRANE

An expression is a formula for calculating a value, it contains a sequence of operands and operators. Operands can contain function calls, variables, constants, and even other expressions. Operators define actions that must be performed on operands.

In the following expression, plus (+) is the operator, and A and B are operands:

A + B

There are four main types of expressions in FORTRAN:
1. Arithmetic expressions
2. Symbolic expressions
3. Relationship expressions
4. Logical expressions

Each type of expression works with a specific type of operand and uses a certain type of operator. The result of the calculation of each expression is a value of a certain type.

Expressions are not operators, but can be included in them as parts of them. In the following example, the entire string is an operator, but only part of it after the equal sign is an expression:

X = 2.0 / 3.0 + A + B

For a detailed discussion of expressions in MS-Fortran, see Part 2, Terms and Concepts.

Fortran Names

Names refer to variables, arrays, functions, or subroutines in your program, regardless of whether they are defined by you or by MS-Fortran itself. The name in Fortran contains a sequence of alphanumeric characters. Name restrictions are:
1. The maximum number of characters in the name does not exceed 1320 (twenty lines of 66 characters each).
2. The initial character must be a letter, the sequence of characters must be alphanumeric.
3. Spaces are ignored.
4. The first six characters are significant, the rest are ignored.

Given these limitations on the name, any sequence of characters can be used as a name in Fortran. There are no reserved names like in other languages.

Sequences of alphabetic characters used by the MS-Fortran compiler as keywords are not confused with user names. The compiler distinguishes keywords by their context and therefore there are no restrictions on the use of names by users. Therefore, for example, in the program there can be arrays with the names IF, READ or GOTO and errors do not occur (until they change the rule to which all arrays obey). However, the use of keywords as user names interferes with the "readability" of programs, and should be avoided.

For details on the scope and use of names in MS-Fortran, see Part 2, Terms and Concepts.

Types of FORTRANE

The data in MS-Fortran is one of six basic types:
1. Integers (INTEGER * 2 and INTEGER * 4)
2. Real usual accuracy (REAL * 4 or REAL)
3. Real double precision (REAL * 8 or DOUBLE PRECISION)
4. Comprehensive (COMPLEX * 8 and COMPLEX * 16)
5. Logical (LOGICAL * 2 and LOGICAL * 4)
6. Character (CHARACTER)

Data types are declared. If it is not declared, then the data type is determined by the first letter of the name (by default or from the IMPLISIT operator). The type declaration operator may also include dimension information.

For more complete information on data types, see Part 2. For a detailed description of the operator, a description of the type, see Part 3, "Operators".

Strings in FORTRAN

The string consists of a sequence of characters. Characters after the 72nd in the line are ignored, a line shorter than 72 characters is considered filled with spaces. It was adopted at the dawn of programming, when input into a computer was carried out with punched cards that had 72 positions for holes punched into them.

ALGORITHMIC COMPILATOR FORTRAN

The position of the character in the Fortran line is important. Characters in positions 1 through 5 are identified as operator labels, characters in position 6 are signs of continuation, and characters in positions 7 through 72 are actually Fortran operators. Comments are identified by the "C" symbol or an asterisk "*" in the first position, and the meta commands by the dollar sign in the first position.

With a few exceptions, spaces are not significant in FORTRAN. Tabs are important in some of the circumstances described in Part 2, Terms and Concepts.

The Fortran lines are the following:
1. The meta command line.
2. Comment line.
3. Start line (operator).
4. Continue string.

The meta command in the first position has a dollar sign and it controls the passage of the MS-Fortran compiler.

In the comment line in the first position "C", "C" or an asterisk, or the entire line is empty and is ignored during processing.

The initial line of the operator has a space or zero in the 6th position and all spaces or operator marks in the positions from 1st to 5th.

The continuation line is not a meta-command line, not a comment line, nor an initial line. She has from first to fifth position spaces, and in the sixth character, different from space or zero.

See Part 2 "Terms and Concepts" for details on the use of different types of MS-Fortran lines and how to compose programs and joint parts of programs from operators.

Symbols in FORTRAN

Basically, Fortran programs are a sequence of characters. When these characters are processed by the compiler, they are interpreted in different contexts as characters, names, labels, constants, strings, and operators.

The symbols used in the texts of programs on MS-Fortran refer to the ASCII character set, the full list of which is given in Appendix C “ASCII Character Codes”. However, the character set can be divided into three main groups:
1. 52 small and large Latin letters (from A to Z and from a to z)
2. 10 digits (from 0 to 9)
3. Special characters (all other printable characters from the ASCII character set).

For more information on the use of symbols in MS-Fortran see Part 2, Terms and Concepts.


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Programming Languages and Methods / Translation Theory

Terms: Programming Languages and Methods / Translation Theory