Translation of Semantics with Applications【持续更新】

来源:互联网 发布:德兴软件ui设计师 编辑:程序博客网 时间:2024/05/19 20:42

Chapter 1

Introduction

The purpose of this book is:
- to describe some of the main ideas and methods used in semantics,
- to illustrate these on interesting applications,and
- to investigate the relationship between the various methods.

这本书的目的在于:

  • 描述一些语义学当中的主要思想与方法
  • 通过一些有趣的应用来阐明这些思想与方法
  • 研究多种方法之间的关系

Formal semantics is concerned with rigorously specifying the meaning, or behaviour, of programs, pieces of hardware etc. The need for rigour arises because
- it can reveal ambiguities and subtle complexities in apparently crystal clear defining documents(for example programming language manuals), and
- it can form the basis for implementation, analysis and verification(in particular proofs of correctness).

正规的语义是与程序严格指定的意义、行为以及硬件的各个部分息息相关的。这种精确需求的产生是因为

  • 将不确定的微小的复杂性揭示为清晰明白的定义文件(例如程序语言手册)
  • 构成执行、分析和核实的基本原理(尤其是正确性证明)

We will use informal set theoretic notation(reviewed in Appendix A) to represent semantic concepts.This will suffice in this book but for other purposes greater notational precision(that is,formality) may be needed,for example when processing semantic descriptions by machine as in semantics directed compiler-compilers or machine assisted proof checkers.

我们会使用非正式的建立理论表示法(收录于附录A)来描述语义学概念。这种表示法在本书中已经足够,但是更好的精确表示法(意味着更加正式)在其他用途中也是需要的,例如用机器(如通过语义制导的一个或多个编译器或者协助证明的机器)处理语义描述。

1.1 Semantic description methods

It is customary to distinguish between the syntax and the semantics of a programming language.The syntax is concerned with the grammatical structure of programs.So a syntactic analysis of the program

z:=x;x:=y;y:=z

will realize that it consists of three statements separated by the symbol ‘;’.Each of these statements has the form of a variable followed by the composite symbol ‘:=’ and an expression which is just a variable.

通常来说一门编程语言要区分其语法和语义的不同。语法主要涉及的是程序的语法结构。因此对于

z:=x;x:=y;y:=z

这段代码的语法分析体现为这段程序由被’;’分隔的三条语句组成。每条语句都由一个变量接一个合成符号’:=’再加一个表达式(这里是一个变量)组成。

The semantics is concerned with the meaning of grammatically correct programs.So it will express that the meaning of the above program is to exchange the values of the variables x and y(and setting z to the final value of y).If we were to explain this in more detail we would look at the grammatical structure of the program and use explanations of the meanings of
- sequences of statements separated by ‘;’,and
- a statement consisting of a variable followed by ‘:=’ and an expression.

语义学关注点在于语法正确的程序的含义。因此上面程序所表达的含义是交换变量 ‘x’ 和 ‘y’ 的值(并且设定 ‘z’ 为 ‘y’ 的最终值)。如果我们想要解释的更详细就需要看程序的语法结构并通过
- 每个被 ‘;’ 分隔的句子片段
- 一个包含一个变量接着 ‘:=’ 还有一个表达式的语句
的意义来解释。

The actual explanations can be formalized in different ways.In this book we shall consider three approaches.Very roughly,the ideas are as follows:
Operational semantics: The meaning of a construct is specified by the computation it induces when it is executed on a machine.In particular,it is of interest how the effect of a computation is produced.
Denotational semantics: Meanings are modelled by mathematical objects that represent the effect of executing the constructs.Thus only the effect is of interest,not how it is obtained.
Axiomatic semantics: Specific properties of the effect of executing the constructs are expressed as assertions.Thus there may be aspects of the executions that are ignored.
To get a feeling for their different nature let us see how they express the meaning of the example program above.

准确的解释可以通过很多方法形成。在这本书中我们仅考虑三种方法。粗略的说,分别是如下三种:
操作性语义:一个概念的意义是由当它在机器上执行时所引起的运算来定义的。而它主要关心的是计算的影响是 怎样 产生的
标志性语义:

To get a feeling for their different nature let us see how they express the meaning of the example program above.

Operational semantics (Chapter 2)

An operational explanation of the meaning of a construct will tell how to execute it :
- To execute a sequence of statements separated by ‘;’ we execute the individual statements one after the other and from left to right.
- To execute a statement consisting of a variable followed by ‘:=’ and another variable we determine the value of the second variable and assign it to the first variable.
We shall record the execution of the example program in a state where x has the value 5,y the value 7 and z the value 0 by the following “derivation sequence”:这里写图片描述
In the first step we execute the statement z:=x and the value of z is changed to 5 whereas those of x and y are unchanged.The remaining program is now x:=y;y:=z.After the second step the value x is 7 and we are left with the program y:=z.The third and final step of the computation will change the value of y to 5.Therefore the initial values of x and y have been exchanged ,using z as a temporary variable.
This explanation gives an abstraction of how the program is executed on a machine.It is important to observe that it is indeed an abstraction : we ignore details like use of registers and addresser for variables.So the operational semantics is rather independent of machine architectures and implementation strategies.
In Chapter 2 we shall formalize this kind of operational semantics which is often called structural operational semantics (or small-step semantics).An alternative operational semantics is called natural semantics (or big-step semantics) and differs from the structural operational semantics by huding even more execution details.In the natural semantics

0 0
原创粉丝点击