The most accessible programming language for beginners is Pascal. This is due at least to the fact that it is studied in the upper grades of secondary schools, as well as in the first courses at the university. It is used as a base for mastering many other languages. However, it is now irrational to use it as the main one for development, since the technical equipment has gone far ahead.
Now there are quite a few tools that preserve syntax. They differ only in the programming environment of a language such as Pascal. The structure of the program will be studied during the article. As a rule, acquaintance with programming begins with the program βHello World!β.
Language history
Pascal was born in 1970 thanks to, oddly enough, Niklaus Virtu. The name of the language is given in honor of Blaise Pascal - a great man originally from France. This is justified by the fact that the scientist created the world's first machine, which was able to add and subtract numbers.
The development of the language was conducted from 1968 to 1969. The first mention appeared in 1970. The creator, introducing his "child", focused on the programming style, as well as on data input in Pascal. The program structure was also developed by Wirth. It has simple syntax and semantics. The direct "descendant" of Pascal is the language of Modula-2. Wirth also became its developer.
Grammar rules
It should be noted that the structure of the program is not so complicated in this language. In Pascal, the author laid down the use of only three main points - the title, description and operator.
- Heading. Here you must specify the name of the program, but this item is not the main one. It is created only if the developer wishes. To a large extent, this depends on the programming environment. Turbo Pascal does not need it. But in ETH, you must create a string without fail. Only numbers, letters and the underscore β_β are allowed.
- Description. In this block, all available variables (arrays), labels, etc. are indicated.
- Operator. The structure of the Pascal program includes a description of the operators in brackets BEGIN-END.
How many will be in one line does not matter. The main thing - after the end of each team to put a special character - a semicolon. In addition, the language is case-insensitive: there is no difference between the Var, vAr, and vaR operator.
Syntax and semantics
The main value when working with the programming environment is the alphabet. It should be remembered that it consists of:
- Latin characters, both lowercase and uppercase;
- space bar
- underscore;
- Arabic numerals
- mathematical signs;
- delimiters (their list includes a period, a comma, etc.);
- qualifiers;
- service words (operators).
The structure of the program on Turbo Pascal is no different from the structure on PascalABC. The difference is in their external data, nothing more. When specifying a name for a variable and other types, it must be remembered that the name should not start with a number, the underscore can be in any position, and only letters of the Latin alphabet are allowed from alphabetic symbols .
Comments on strings are enclosed either in curly brackets or in round asterisks with a sign: (* .. *).
Data types
The structure of a Pascal program also involves looking at objects such as data types. They are of three types:
- logical (truth and falsehood);
- numeric (Arabic numbers);
- symbolic (using a, b, c, etc.).
At the same time, the second type is divided into subtypes: integer and material. Certain operators correspond to them: Integer and Real, respectively. Character characters are also divided into single characters and strings. This refers to data types such as (in the first case) the number 1, the letter a or A, and (in the second) whole phrases or expressions. They are written to the program under the names Char and Spring.
Values ββalso have their own classification. They are divided into constants and variables. The difference between them is significant. The first implies the meaning of the letter, which does not change during the execution of the program. And the variables are assigned a value during execution using a special character - a colon.
Comments
In order to achieve a complete understanding of the program and all its processes, the comment function is used. They, as already mentioned above, are placed in braces. This is especially important if a beginner is looking at the code. Because, using this option, you can easily find an error in a ready-made program, based on what is written in the comments. Moreover, they will help the developer quickly figure out the software code over time.
The structure of the program in Pascal allows you to assign comments to the data structure specified in the second block. There you must enter a text that will contain the purpose of each operator and how it is used in the future.
A beginner will be able to navigate in brackets BEGIN-END comment next to them. This will be especially useful in a cycle-oriented program. So it will be easier to understand which block of statements is completed.
Comments are not read by the programming environment, so they can take any number of days and are not limited in literal quantity.
Punctuation
The structure of the program in Pascal has its own punctuation, however, this is not surprising. The most used character is a semicolon. It is placed after each description of the Label, Type, Const, Var blocks, etc., however, the sign is not needed after the word itself. After Begin, it is not installed; after END it is set only if the program is not finished yet. In code where there are loops and, accordingly, Then and Else are used, after these words a semicolon is not needed.
At the end of the program, after END, you need to set a point, otherwise the programming environment will not understand that the code has completed.
Data input and output
The program structure in Pascal allows you to enter data in three different ways. Among them:
- Using Readln, Read.
- Using an assignment character - a colon.
- Constant. In this case, data is entered in the var parameter.
The output of the obtained information can be performed using a combination of Write and Writeln operators. In some cases, it may be absent, but this only means that it is already built into the production method.