Modula-2 (на английском языке)

2019-09-19СтудИзба

Описание файла

Документ из архива "Modula-2 (на английском языке)", который расположен в категории "". Всё это находится в предмете "языки программирования" из 7 семестр, которые можно найти в файловом архиве МГУ им. Ломоносова. Не смотря на прямую связь этого архива с МГУ им. Ломоносова, его также можно найти и в других разделах. .

Онлайн просмотр документа "Modula-2 (на английском языке)"

Текст из документа "Modula-2 (на английском языке)"

Introduction

Modula-2 grew out of a practical need for a general, efficiently implementable systems programming language for minicomputers. Its ancestors are Pascal and Modula. From the latter it has inherited the name, the important module concept, and a systematic, modem syntax, from Pascal most of the rest. This includes in particular the data structures, i.e. arrays, records, variant records, sets, and pointers. Structured statements include the familiar if, case, repeat, while, for, and with statements. Their syntax is such that every structure ends with an explicit termination symbol.

The language is essentially machine-independent, with the exception of limitations due to wordsize. This appears to be in contradiction to the notion of a system-programming language, in which it must be possible to express all operations inherent in the underlying computer. The dilemma is resolved with the aid of the module concept. Machine-dependent items can be introduced in specific modules, and their use can thereby effectively be confined and isolated. In particular, the language provides the possibility to relax rules about data type compatibility in these cases. In a capable system-programming language it is possible to express inpuut/output conversion procedures, file handling routines, storage allocators, process schedulers etc. Such facilities must therefore not be included as elements of the language itself, but appear as (so-called low-level) modules which are components of most programs written. Such a collection of standard modules is therefore an essential part of a Modula-2 implementation.

The concept of processes and their synchronization with signals as included in Modula is replaced by the lower-level notion of coroutines in Modula-2. It is, however, possible to formulate a (standard) module that implements such processes and signals. The advantage of not including them in the language itself is that the programmer may select a process scheduling algorithm tailored to his particular needs by programming that module on his own. Such a scheduler can even be entirely omitted in simple (but frequent) cases, e.g. when concurrent processes occur as device drivers only.

A modern system programming language should in particular also facilitate the construction of large programs, possibly designed by several people. The modules written by individuals should have well-specified interfaces that can be declared independently of their actual implementations. Modula-2 supports this idea by providing separatet definition and implementation modules. The former define all objects exported from the corresponding implementation module; in some cases, such as procedures and types, the definition module specifies only those parts that are relevant to the interface, i.e. to the user or client of the module.

Syntax

A language is an infinite set of sentences, namely the sentences well formed according to its syntax. In Modula-2, these sentences are called compilation units. Each unit is a finite sequence of symbols from a finite vocabulary. The vocabulary of Modula-2 consists of identifiers, numbers, strings, operators, and delimiters. They are called lexical symbols and are composed of sequences of characters. (Note the distinction between symbols and characters.)

To describe the syntax, an extended Backus Naur Formalism called EBNF is used. Angular brackets [ ] denote optionality of the enclosed sentential form, and curly brackets { } denote its repetition (possibly 0 times). Syntactic entities (non terminal symbols) are denoted by English words expressing their intuitive meaning. Symbols of the language vocabulary (terminal symbols) are strings enclosed in quote marks or words written in capital letters, so called reserved words.

Vocabulary and representation

The representation of symbols in terms of characters depends on the underlying character set. The ASCII set is used in this reference text, and the following lexical rules must be observed. Blanks must not occur within symbols (except in strings). Blanks and line breaks are ignored unless they are essential to separate two consecutive symbols.

Identifiers

Identifiers are sequences of letters and digits. The first character must be a letter.

ident = letter {letter | digit}

Examples: x scan Modula ETH GetSymbol firstLetter

Numbers

Numbers are (unsigned) integers or real numbers. Integers are sequences of digits. If the number is followed by the letter B, it is taken as an octal number; if it is followed by the letter H, it is taken as a hexadecimal number; if it is followed by the letter C, it denotes the character with the given (octal) ordinal number (and is of type CHAR). An integer i in the range 0 <= i <= MaxInt can be considered as either of type INTEGER or CARDINAL; if it is in the range MaxInt < i <= MaxCard, it is of type CARDINAL. For 16-bit computers: MaxInt = 32767, MaxCard = 65535.

A real number always contains a decimal point. Optionally it may also contain a decimal scale factor. The letter E is pronounced as "ten to the power of". A real number is of type REAL.

number = integer | real.

integer = digit {digit} | octalDigit {octalDigit} ("B" | "C") | digit {hexDigit} "H".

real = digit {digit} "." {digit} [ScaleFactor].

ScaleFactor = "E" ["+"|"-"] digit {digit}.

hexDigit = digit | "A" | "B" | "C" | "D" | "E" | "F".

digit = octalDigit | "8" | "9". |

octalDigit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7".

Examples: 1980 3764B 7BCH 33C 12.3 45.67E 8

Strings

Strings are sequences of characters enclosed in quote marks. Both double quotes and single quotes (apostrophes) may be used as quote marks. However, the opening and closing marks must be the same character, and this character cannot occur within the string. A string must not extend over the end of a line.

string = '"' {character} '"' | "'" {character} "'"

A string consisting of n characters is of type ARRAY [0..n-1] OF CHAR

Examples: "MODULA" "Don't worry!" 'codeword"Barbarossa"'

Operators and delimiters

Operators and delimiters are the special characters, character pairs, or reserved words listed below. These reserved words consist exclusively of capital letters and must not be used in the role of identifiers. The symbols # and <> are synonyms, and so are &, AND, and ~, NOT.

+ = AND FOR QUALIFIED

- # ARRAY FORWARD RECORD

* < BEGIN FROM REPEAT

/ > BY IF REM

:= <> CASE IMPLEMENTATION RETRY

& <= CONST IMPORT RETURN

. >= DEFINITION IN SET

, .. DIV LOOP THEN

; : DO MOD TO

( ) ELSE MODULE TYPE

[ ] ELSIF NOT UNTIL

{ } END OF VAR

^ | EXCEPT OR WHILE

~ EXIT PACKEDSET WITH

EXPORT POINTER

FINALLY PROCEDURE

Additional reserved words defined by the ISO generics language extension

GENERIC

Additional reserved words defined by the ISO object oriented language extension

AS INHERIT TRACED

ABSTRACT OVERRIDE UNSAFEGUARDED

CLASS READONLY

GUARD REVEAL

Comments

Comments may be inserted between any two symbols in a program. They are arbitrary character sequences opened by the bracket (* and closed by *). Comments may be nested, and they do not affect the meaning of a program.

Declarations and scope rules

Every identifier occurring in a program must be introduced by a declaration, unless it is a standard identifier (see below). Declarations also serve to specify certain permanent properties of an object, such as whether it is a constant, a type, a variable, a procedure, or a module.

The identifier is then used to refer to the associated object. This is possible in those parts of a program only which are within the so called scope of the declaration. In general, the scope extends over the entire block (procedure or module declaration) to which the declaration belongs and to which the object is local. The scope rule is augmented by the following cases:

  1. If an identifier x defined by a declaration D1 is used in another declaration (not statement) D2, then D1 must textually precede D2.

  2. A type T1 can be used in a declaration of a pointer type T which textually precedes the declaration of T1, if both T and T1 are declared in the same block. This is a relaxation of rule 1.

  3. If an identifier defined in a module M1 is exported, the scope expands over the block which contains M1. If M1 is a compilation unit, it extends to all those units which import M1.

  4. Field identifiers of a record declaration are valid only in field designators and in with statements referring to a variable of that record type.

An identifier may be qualified. In this case it is prefixed by another identifier which designates the module in which the qualified identifier is defined. The prefix and the identifier are separated by a period.

qualident = ident {"." Ident}.

Standard identifiers

Standard identifiers are considered to be predeclared, and they are valid in all parts of a program. For this reason they are called pervasive.

ABS BITSET BOOLEAN CARDINAL

CAP CHR CHAR COMPLEX

CMPLX DEC DISPOSE EXCL

FALSE FLOAT HALT HIGH

IM INC INCL INT

INTERRUPTIBLE INTEGER LENGTH LFLOAT

LONGCOMPLEX LONGREAL MAX MIN

NEW NIL ODD ORD

PROC PROTECTION RE REAL

SIZE TRUE TRUNC UNINTERRUPTIBLE

VAL

The pervasive identifiers COMPLEX, CMPLX, IM, INT, INTERRUPTIBLE, LENGTH, LFLOAT, LONGCOMPLEX, LONGREAL, PROTECTION, RE and UNINTERRUPTIBLE were added for ISO Modula-2.

Constant declarations

Constants are objects that have a specific value assigned at compile time. Constants cannot change during the execution of the program.

The format of the constant declaration is:

CONST {constdec}

where constdec is:

identifier = value;

The identifier is the name of the constant you are defining.

Simple constants

For simple types, value is an expression giving the value of the constant. The expression must be made up of constants only, so that the compiler can evaluate it at compile time.

The following are examples of simple constants:

CONST

   One = 1;

   Pi = 3.14159;

   PiOver2 = Pi / 2.0;

   Debug = TRUE;

   Message = "That's not right!";

Structured constants

You can also create constants of array and record types.  The value for these structured types consists of a constant constructor.

If a component is a structured type, the value for that component must also be a constant constructor.

When creating structured constant types, you must specify the type of the constant.

Array constant constructors take the following form:

TypeName{element {, element}}

where element is

constantValue [BY repeatValue]

Record constant constructors take the following form.

TypeName{element {, element}}

where element is

constantValue

where constantValue is a valid constant expression for the field type.

The following are examples of structured constants:

TYPE

  rectype =

 RECORD

  A , B : INTEGER;

  C : CHAR

  END;

  arraytype1 = ARRAY [1..2], [1..2] OF INTEGER;

  arraytype2 = ARRAY [1..2] OF rectype;

  arraytype3 = ARRAY [0..255] OF CARDINAL;

CONST

 rtc = rectype{1, 2, '*'};

 atc1 = arraytype1{{1, 12},{1, 23}};

 atc2 = arraytype2{{1, 2, '*'}, rectype{1, 2, '*'}};

 atc3 = arraytype3{1, 2 BY 254, 2};

Note that when an element of a structured type is itself a structure it is optional to prefix the {with the type name of the structure if it has a type name. The type name is not necessary since the type of the constant to follow is known from the declaration of the type. This also allows you to have anonymous types as elements and still be able to create a constant.

Variant Record constants

If you are creating a constant of a record type that has variants, you must specify a value for the tag field of each variant in the record.  This is true even if the tag field is not named.

The fields following the tag field must comply with the types of the fields for the variant selected by the value of the tag field.

The following are examples of variant record constants:

TYPE varrec =

RECORD

Свежие статьи
Популярно сейчас
А знаете ли Вы, что из года в год задания практически не меняются? Математика, преподаваемая в учебных заведениях, никак не менялась минимум 30 лет. Найдите нужный учебный материал на СтудИзбе!
Ответы на популярные вопросы
Да! Наши авторы собирают и выкладывают те работы, которые сдаются в Вашем учебном заведении ежегодно и уже проверены преподавателями.
Да! У нас любой человек может выложить любую учебную работу и зарабатывать на её продажах! Но каждый учебный материал публикуется только после тщательной проверки администрацией.
Вернём деньги! А если быть более точными, то автору даётся немного времени на исправление, а если не исправит или выйдет время, то вернём деньги в полном объёме!
Да! На равне с готовыми студенческими работами у нас продаются услуги. Цены на услуги видны сразу, то есть Вам нужно только указать параметры и сразу можно оплачивать.
Отзывы студентов
Ставлю 10/10
Все нравится, очень удобный сайт, помогает в учебе. Кроме этого, можно заработать самому, выставляя готовые учебные материалы на продажу здесь. Рейтинги и отзывы на преподавателей очень помогают сориентироваться в начале нового семестра. Спасибо за такую функцию. Ставлю максимальную оценку.
Лучшая платформа для успешной сдачи сессии
Познакомился со СтудИзбой благодаря своему другу, очень нравится интерфейс, количество доступных файлов, цена, в общем, все прекрасно. Даже сам продаю какие-то свои работы.
Студизба ван лав ❤
Очень офигенный сайт для студентов. Много полезных учебных материалов. Пользуюсь студизбой с октября 2021 года. Серьёзных нареканий нет. Хотелось бы, что бы ввели подписочную модель и сделали материалы дешевле 300 рублей в рамках подписки бесплатными.
Отличный сайт
Лично меня всё устраивает - и покупка, и продажа; и цены, и возможность предпросмотра куска файла, и обилие бесплатных файлов (в подборках по авторам, читай, ВУЗам и факультетам). Есть определённые баги, но всё решаемо, да и администраторы реагируют в течение суток.
Маленький отзыв о большом помощнике!
Студизба спасает в те моменты, когда сроки горят, а работ накопилось достаточно. Довольно удобный сайт с простой навигацией и огромным количеством материалов.
Студ. Изба как крупнейший сборник работ для студентов
Тут дофига бывает всего полезного. Печально, что бывают предметы по которым даже одного бесплатного решения нет, но это скорее вопрос к студентам. В остальном всё здорово.
Спасательный островок
Если уже не успеваешь разобраться или застрял на каком-то задание поможет тебе быстро и недорого решить твою проблему.
Всё и так отлично
Всё очень удобно. Особенно круто, что есть система бонусов и можно выводить остатки денег. Очень много качественных бесплатных файлов.
Отзыв о системе "Студизба"
Отличная платформа для распространения работ, востребованных студентами. Хорошо налаженная и качественная работа сайта, огромная база заданий и аудитория.
Отличный помощник
Отличный сайт с кучей полезных файлов, позволяющий найти много методичек / учебников / отзывов о вузах и преподователях.
Отлично помогает студентам в любой момент для решения трудных и незамедлительных задач
Хотелось бы больше конкретной информации о преподавателях. А так в принципе хороший сайт, всегда им пользуюсь и ни разу не было желания прекратить. Хороший сайт для помощи студентам, удобный и приятный интерфейс. Из недостатков можно выделить только отсутствия небольшого количества файлов.
Спасибо за шикарный сайт
Великолепный сайт на котором студент за не большие деньги может найти помощь с дз, проектами курсовыми, лабораторными, а также узнать отзывы на преподавателей и бесплатно скачать пособия.
Популярные преподаватели
Добавляйте материалы
и зарабатывайте!
Продажи идут автоматически
5280
Авторов
на СтудИзбе
419
Средний доход
с одного платного файла
Обучение Подробнее