Therese Hardin - Concepts and Semantics of Programming Languages 1

Здесь есть возможность читать онлайн «Therese Hardin - Concepts and Semantics of Programming Languages 1» — ознакомительный отрывок электронной книги совершенно бесплатно, а после прочтения отрывка купить полную версию. В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: unrecognised, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Concepts and Semantics of Programming Languages 1: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Concepts and Semantics of Programming Languages 1»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

This book – the first of two volumes – explores the syntactical constructs of the most common programming languages, and sheds a mathematical light on their semantics, while also providing an accurate presentation of the material aspects that interfere with coding. <p><i>Concepts and Semantics of Programming Languages 1</i> is dedicated to functional and imperative features. Included is the formal study of the semantics of typing and execution; their acquisition is facilitated by implementation into OCaml and Python, as well as by worked examples. Data representation is considered in detail: endianness, pointers, memory management, union types and pattern-matching, etc., with examples in OCaml, C and C++. The second volume introduces a specific model for studying modular and object features and uses this model to present Ada and OCaml modules, and subsequently Java, C++, OCaml and Python classes and objects. <p>This book is intended not only for computer science students and teachers but also seasoned programmers, who will find a guide to reading reference manuals and the foundations of program verification.

Concepts and Semantics of Programming Languages 1 — читать онлайн ознакомительный отрывок

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Concepts and Semantics of Programming Languages 1», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Using Python, we define the following classes to represent the constructors of the set Exp1:

Python class Cstel: def __init__(self,cste): self.cste = cste class Var1: def __init__(self,symb): self.symb = symb class Plusl: def __init__(self,exp1,exp2): self.exp1 = exp1 self.exp2 = exp2 class Bang1: def __init__(self,symb): self.symb = symb

For example, the expression e 1= !x + y defined in example 2.1 is written as:

Python ex_expl = Plusl(Bangl(“x”),Varl(“y”))

Using OCaml, the type of arithmetic expressions is defined directly as:

OCaml type ’a exp1 = Cstel of int | Var1 of ’a | Plusl of ’a expl * ’a expl | Bangl of ’a

Values of this type are thus obtained using either the Cste1 constructor applied to an integer value, in which case they correspond to a constant expression, or using the Var1 constructor applied to a value of type ’a, corresponding to the type used to represent identifiers (the type ’a exp1 is thus polymorphic, as it depends on another type), or by applying the Plus1 constructor to two values of the type ’a expl, or by applying the Bang1 constructor to a value of type ’a. For example, the expression e 1= ! x + y is written as:

OCaml let ex_exp1 = Plus1 (Bang1 (“x”), Var1 (“y”)) val ex_exp1 : string exp1

2.2.2. Values

Given a state (Env , Mem), we determine the evaluation semantics of an expression e ∈ Exp 1by computing the value of e in this state, i.e. by evaluating e in this state. Values may be relative integers or references, hence V= ℤ U R. An additional, specific value Err is added to the set V; this result is returned as the value of “meaningless” expressions. The result of the evaluation of an expression in Exp 1will therefore be a value belonging to the set картинка 19

Values in Vare either relative integers or references. By defining a sum type, these two collections of values can be grouped into a single type.

Python class CInt1: def __init__(self,cst_int): self.cst_int = cst_int class CRef1: def __init__(self,cst_adr): self.cst_adr = cst_adr

Each class possesses a (object) constructor with the same name as the class: the constant k obtained from integer n (or, respectively, from reference r) is thus written as CInt1( n ) (respectively, CRef1( r )), and this integer (respectively, reference) can be accessed from (the object) k by writing k . cst_int(respectively k . cst_adr). With OCaml, the type of elements in Vis defined directly, as follows:

OCaml type ’a constl = CIntI of int | CRefl of ‘a

A value of this type is obtained either using the constructor CInt1applied to an integer value or using the constructor CRef1applied to a value of type ’a corresponding to the type used to represent references.

A type grouping the elements of картинка 20is defined by applying the same method:

Python class VCste1: def __init__(self,cste): self.cste = cste class Erreur1: pass

An element v in картинка 21is either a value in Vobtained from a constant k and written as VCste1(k), or an object in the class Erreur1 (passis used here to express the fact that the (object) constructor has no argument). With OCaml, the type of the elements in 𝕧 is defined directly as follows:

OCaml type ’a valeursl = VCstel of ’a constl | Erreur1

2.2.3. Evaluation semantics

There are several formalisms that may be used to describe the evaluation of an expression. These will be introduced later. Let us construct an evaluation function:

The evaluation of the expression e in the environment Env and memory state Mem - фото 22

The evaluation of the expression e in the environment Env and memory state Mem is denoted as картинка 23with vV. Table 2.2contains the recursive definition of the function картинка 24

Table 2.2. Evaluation of the expressions of Exp 1

картинка 25 ( k ∈ ℤ)
картинка 26 if xXand x dom( Env)
if x X and x dom Env - фото 27 if xX and x ∉ dom( Env)
Concepts and Semantics of Programming Languages 1 - изображение 28 Concepts and Semantics of Programming Languages 1 - изображение 29
Concepts and Semantics of Programming Languages 1 - изображение 30 Concepts and Semantics of Programming Languages 1 - изображение 31
Concepts and Semantics of Programming Languages 1 - изображение 32 картинка 33
картинка 34 картинка 35

The value of an integer constant is the integer that it represents. The value of an identifier is that which is bound to it in the environment, or Err. The value of an expression constructed with an addition symbol and two expressions e 1and e 2is obtained by adding the relative integers resulting from the evaluations of e 1and e 2; the result will be Err if e 1or e 2is not an integer. The value of ! x is the value stored at the reference Env( x ) when x is a mutable variable, and Err otherwise.

Thus, if e is evaluated as a reference, then e can only be an identifier. Furthermore, certain expressions in Exp 1are syntactically correct, but meaningless: for example, the expression ! x when x is not a mutable variable, i.e. when x does not bind a reference in the environment, or x 1+ x 2when x 1(or x 2) is a mutable variable. On the other hand, ! x + y is a meaningful expression that denotes a value when y binds an integer and x binds a reference to an integer.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Concepts and Semantics of Programming Languages 1»

Представляем Вашему вниманию похожие книги на «Concepts and Semantics of Programming Languages 1» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Concepts and Semantics of Programming Languages 1»

Обсуждение, отзывы о книге «Concepts and Semantics of Programming Languages 1» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x