Home  >  Article  >  Introduction to PASCAL language basics

Introduction to PASCAL language basics

DDD
DDDOriginal
2023-06-14 17:46:555538browse

Introduction to PASCAL language basics

PASCAL language is also an algorithmic language. It is developed by N. It was designed by Professor Niklaus Wirth in 1968 and officially published in 1971. In 1975, the PASCAL language was modified as the "Standard PASCAL Language".

PASCAL language is developed on the basis of ALGOL 60. It is a structured programming language that can be used to write applications. It is also a system programming language that can be used to write sequential system software (such as compiler). It has powerful functions and simple compilation procedures. It was the most influential algorithm language in the 1970s.

Characteristics of Pascal language

From the user's perspective, the PASCAL language has the following main features:

⒈It is a structure ized language. The PASCAL language provides the ability to directly implement statements of three basic structures and to define "procedures" and "functions" (subprograms). Structured programs can be easily written. You can completely eliminate the use of GOTO statements and labels when writing programs. This makes it easy to ensure the correctness and readability of the program. The PASCAL language emphasizes reliability, ease of verification, conceptual clarity, and simplification of implementation. In terms of structuring, it is better than others (such as BASIC, FORTRAN77).

⒉There are rich data types. PASCAL provides integers, real types, character types, Boolean types, enumeration types, subrange types, and array types, collection types, record types, and file types composed of the above types of data. In addition, pointer types are provided that are not found in many other languages. Worth has a famous formula: "Algorithm + data structure = program". The importance of studying data in program design is pointed out. The rich data structure and the above-mentioned structural properties allow PASCAL to be easily used to describe complex algorithms and obtain higher-quality programs.

⒊It can be applied to the fields of numerical operations and non-numeric operations. Some languages ​​(such as FORTRAN 66, ALGOL 60) are only suitable for numerical calculations, while some languages ​​(such as COBOL) are suitable for commercial data processing and management fields. PASCAL has strong functions and can be widely used in various fields. PASCAL language can also be used to assist design and realize computer graphics functions.

⒋The writing format of the PASCAL program is relatively free. Unlike FORTRAN and COBOL, there are no strict regulations on the writing format of the program. PASCAL allows multiple statements to be written on one line, and one statement can be written on multiple lines. This allows the PASCAL program to be written as beautifully as poetry and easy to read.

Due to the above characteristics, many schools choose PASCAL as a main language in programming courses. It can give students rigorous and good basic training in programming. Develop students' structured programming style. But it also has some shortcomings, such as its poor file processing capabilities. 3. The basic structure of Pascal language program

Any programming language has its own set of symbols and rules. PASCAL language must also use the symbols and rules specified by itself to write programs. Although the number and form of tokens used in different versions of the PASCAL language vary, their basic components generally comply with the provisions of standard PASCAL, except that some extended functions are different. Let's first understand the basic structure of the Pascal language program.

Usage of Turbo Pascal language system

Currently, the commonly used Pascal language systems are Turbo Pascal7.0 and Borland Pascal 7.0. Let’s learn the Turbo Pascal 7.0 system. usage of. 1. System startup

Run the startup program TURBO.EXE in the system directory to start the system. The integrated environment shown in Figure 1 appears on the screen.

2. Introduction to Turbo Pascal System Integration Environment

The top line is the main menu. The blue box in the middle is the editing window, and the program can be edited in each editing window. The bottom line is the prompt line, which displays the shortcut keys for commonly used commands in the system. For example, the shortcut key for saving the file in the current editing window is F2, the shortcut key for obtaining system help is F1, etc.

3. Create a new program window

Press F10 to enter the main menu, select the FILE menu, and execute the New command. You can create a new program window (the default file name is Noname00.pas or Noname01.pas, etc.).

4. Input, edit and run the program

In the current program window, enter the program line by line. In fact, the program window is a full-screen editor. Therefore, the editing method of the program is similar to that of other editors, and will not be repeated here.

After the program input is completed, you generally need to press Alt F9 (or execute the compile command in the compile menu) to compile the program. If the program has a syntax error, the first red error message will be displayed on the first line of the program window. If there are no syntax errors, a dialog box will appear in the center of the window, indicating that the compilation was successful. Next, we can run the program.

You can run the program by pressing ALT R to open the RUN command in the RUN menu, or directly press the shortcut key CTRL F9. Then the running results can be output in the user window. Usually after the program is finished running, the system returns to the integrated environment of the Pascal system, so to view the running results, press ALT F5 to switch the screen to the user screen.

5. Saving and opening programs

When we want to save the program in the program window to disk, we can save the program by pressing the F2 key (or executing the save command in the File menu). When saving a file for the first time, a dialog box will appear on the screen asking for a file name (the default extension is .pas).

When we want to load the PASCAL program in the program file on the disk into the window, we can press F3 (or execute the Open command in the File menu) to load the program. At this time, the system will also pop up a dialog box. box asks for the file name to be opened, or directly selects the desired file in the file dialog list and returns to opening the file.

The first program

When the following program is run, it will prompt you to enter the radius of a circle, and then draw a circle on the screen. After pressing Enter, the program ends and returns to the program window.

Program ex1;
Uses graph;
Var Gm,Gd,R :integer;
Begin
Gd:=0;
Write('Please enter the radius:');readln(R);
Initgraph(Gm,Gd,' ');
Setcolor(Green);
Circle(320,240,R);
Readln;
Closegraph;
End.

Note that if an initialization graphics error occurs when the above program is run, please copy Graph.tpu in the BGI subdirectory EGAVGA.BGI and UNITS subdirectory under the system directory to the BIN directory under the system directory.

The above is the detailed content of Introduction to PASCAL language basics. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to install PascalNext article:How to install Pascal