编程语言的语法与语义

摘自《Formal Syntax and Semantics of Programming Languages 》by Kenneth Slonneger / Barry L. Kurtz
刘建文略译(http://blog.csdn.net/keminlau)

Chapter 1 SPECIFYING SYNTAX

Language provides a means of communication by sound and written symbols. Human beings learn language as a consequence of their life experiences, but in linguistics-the science of languages-the forms and meanings of languages are subjected to a more rigorous examination. This science can also be applied to the subject of this text, programming languages. In contrast to the natural languages, with which we communicate our thoughts and feelings, programming languages can be viewed as artificial languages defined by men and women initially for the purpose of communicating with computers but, as importantly, for communicating algorithms among people.

语言以声音和文字符号的形式提供交流的渠道。人类一般通过生活的体验习得语言,但是在作为一门科学的语言学中,语言的形式和及其含义必须被严格考究 (rigorous examination)。同样的科学对待当然也被应用到本书的主题--编程语言。和自然语言用以交流想法和感觉不同,编程语言可被看成是一个人工语言, 起初定义为为了人机交流,不过现在更重要的是为了在程序员之间交流程序算法。

Many of the methods and much of the terminology of linguistics apply to programming languages. For example, language definitions consist of three components:

语言学的很多方法和术语应用于编程语言。比如,语言定义的三个部分:

1. Syntax refers to the ways symbols may be combined to create well-formed sentences (or programs) in the language. Syntax defines the formal relations between the constituents要素 of a language, thereby providing a structural description of the various expressions that make up legal strings in the language. Syntax deals solely with the form and structure of symbols in a language without any consideration given to their meaning.

语法指用字符组合成合法语句的规则集(KEMIN:字符先通过词法 组词或字串,再由代表不同句子成分的词组合成语句)。语法定义语言的各种要素间的形式关系(KEMIN:什么要素,什么关系?),因此给出了语言中各种不 同的合法的语句的结构描述。语法只关注句法结构,不管其含义,那是语义的事。

2. Semantics reveals透露 the meaning of syntactically valid strings in a language. For natural languages, this means correlating sentences and phrases with the objects, thoughts, and feelings of our experiences. For programming languages, semantics describes the behavior that a computer follows when executing a program in the language. We might disclose揭露 this behavior by describing the relationship between the input and output of a program or by a step-by-step explanation of how a program will execute on a real or an abstract machine.

语义指定一条合法语句的含义。对自然语言来说,短语和语句的含义指相 关的对象、思想和经验感觉;而对编程语言来说,语义描述了计算机执行一个程序时所表现的行为。揭示语义的行为包括描述程序输入输出之间的关系,逐步解说程 序如何在真实或抽象机器的执行过程等。(KEMIN:语义都需要某种实现的。而计算机实际行为,如逻辑运算、给内存保存数据等实现了编程语言的抽象语义) (KEMIN:在这里,语义的存在及重要性是无可非议的了,问题还不清楚它与算法过程有什么关系。)

3. Pragmatics alludes to those aspects of language that involve the users of the language, namely psychological and sociological phenomena such as utility, scope of application, and effects on the users. For programming languages, pragmatics includes issues such as ease of implementation, efficiency in application, and programming methodology.

语用涉及了语言使用者的各种方面的内容,包括心理学上、社会学现象,比如语言的实用性、应用范围和对使用者的作用。对编程语言来说,语用问题指实现的简易性、应用的效率和编程方法论。

Syntax must be specified prior to semantics since meaning can be given only to correctly formed expressions in a language. Similarly, semantics needs to be formulated before considering the issues of pragmatics, since interaction with human users can be considered only for expressions whose meaning is understood. In the current text, we are primarily concerned with syntax and semantics, leaving the subject of pragmatics to those who design and implement programming languages, chiefly compiler writers. Our paramount goal is to explain methods for furnishing装备 a precise definition of the syntax and semantics of a programming language.

语法必须先于语义给出,因为只能给正确形式的表达式指定含义;同样,语义也需要明确后才考虑语用问题,因为使用者只有明白表达式的含义后才能使用语言进行 交流。本书主要讲述语法和语义,语用部分留给语言的设计者和实现者,一般是编译器开发人员。我们的第一目标就是解释装备(furnishing)一个编程 语言的语法和语义的精确定义的方法。

We begin by describing a metalanguage for syntax specification called BNF. We then use it to define the syntax of the main programming language employed in this text, a small imperative language called Wren. After a brief look at variants of BNF, the chapter concludes with a discussion of the abstract syntax of a programming language.

我们先介绍描述语法规范的一种元语言——BNF(巴克斯-诺尔范式)。我们用它来定义本书选用的语言Wren的语法,Wren是种很小的命令式语言。在概览BNF的变种后,我们总结编程语言的抽象语法。

At the simplest level, languages are sets of sentences, each consisting of a finite sequence of symbols from some finite alphabet. Any really interesting language has an infinite number of sentences. This does not mean that it has an infinitely long sentence but that there is no maximum length for all the finite length sentences. The initial concern in describing languages is how to specify an infinite set with notation that is finite. We will see that a BNF grammar is a finite specification of a language that may be infinite.

编程语言的语法与语义相关推荐

  1. 计算机语言与语法,编程语言中语法和语义有什么区别?

    语法是关于语言的结构或语法. 它回答了这个问题:我如何构建一个有效的句子? 所有语言,甚至英语和其他人类(又称"自然")语言都有语法,即定义句子是否正确构造的规则. 以下是一些C语 ...

  2. 语法和语义之间的差异_语法和语义之间的区别

    语法和语义之间的差异 Here you will learn about difference between Syntax and Semantics with example. 在这里,您将通过示 ...

  3. boost::spirit模块使用 phoenix 进行实际表达式评估的语法和语义操作的测试程序

    boost::spirit模块使用 phoenix 进行实际表达式评估的语法和语义操作的测试程序 实现功能 C++实现代码 实现功能 boost::spirit模块使用 phoenix 进行实际表达式 ...

  4. boost::spirit模块演示语法和语义操作的计算器示例

    boost::spirit模块演示语法和语义操作的计算器示例 实现功能 C++实现代码 实现功能 boost::spirit模块演示语法和语义操作的计算器示例 C++实现代码 #define BOOS ...

  5. λ演算的语法和语义_λ和副作用

    λ演算的语法和语义 总览 Java 8添加了诸如lambda和类型推断之类的功能. 这使语言不再那么冗长和简洁,但是它带来了更多的副作用,因为您不必对自己的工作做得那么明确. Lambda的返回类型很 ...

  6. 阐述HTML语言的基本语法规则,HTML基本语法和语义写法规则与实例

    本文对HTML基本语法和语义进行了整理与实例,需要的朋友可以参考下 DOCTYPE DOCTYPE(Document Type) 该声明位于文档中最前面的位置,处于html标签之前,此标签告知浏览器文 ...

  7. Sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux,支持32与64位,支持各种流行编程语言的语法高亮、代码补全等...

    Sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux,支持32与64位,支持各种流行编程语言的语法高亮.代码补全等-- 语法高亮.代码提示补全. ...

  8. 归纳编程语言的语法grammer

    背景: 我是一个系统软件工程师,之前没有使用过python 语言. 但是,最近项目需要使用python 脚本实现自动化测试.于是抽空学习了解了python,同时为了更好的灵活使用编程语言的技巧和了解意 ...

  9. 命题逻辑中的语法与语义,可靠性与完备性

    命题逻辑中的语法与语义,可靠性与完备性 1 导言 初学数理逻辑的时候,一个非常重要的点就是对可靠性与完备性概念的理解,这两个概念极为重要,却又经常让人觉得 难以理解.        说它重要是因为它涉 ...

最新文章

  1. 学习java周期_Java第一作业周期总结
  2. UITableView的cell向左滑出有删除,修改等选项
  3. java55矩阵output_leetcode 59 螺旋矩阵2 Java 用时较短-Go语言中文社区
  4. C/C++语言void及void指针深层探索 .
  5. 前端学习(2347):创建新页面和配置
  6. php多个表中查找数据_Excel实战技巧74: 在工作表中创建搜索框来查找数据
  7. php socket 基础知识
  8. hadoop历史版本,包括大名鼎鼎的hadoop 0.20.2
  9. mysql 5.7 root 修改密码_Mysql5.7忘记root密码及mysql5.7修改root密码的方法
  10. 径流模拟方法探究——P-Ⅲ频率曲线与copula函数
  11. A/B Test(AB测试) 流程、常见面试问题及解答
  12. Vue.js 开篇---Vue的介绍及准备工作
  13. 股票实时行情数据接口编译
  14. GUI学习笔记——04更改背景板颜色,鼠标进入事件
  15. [TS初学]无法重新声明块范围变量
  16. RAID区别和特点(全)
  17. 商协社团大会链接一带一路 万祥军:全国工商联助力发展
  18. 遇到“more than one device/emulator”解决方法
  19. Linux环境搭建:CentOS7安装Oracle
  20. java韩顺平最新教程,Java工程师进阶

热门文章

  1. Mysql 解决emoji表情处理问题 - Incorrect string value: ‘\xF0\x9F\x92\x94‘ for column
  2. Python爬虫编程常见问题解决方法
  3. 微信H5页面嵌入百度地图---解决手机的webKit定位,ios系统对非https网站不提供支持问题
  4. 解决Ubuntu下软件包依赖关系的若干方法
  5. Cocoa Autolayout:内容拥抱与内容压缩阻力优先
  6. 如何检查Django版本
  7. win11wifi总掉线怎么办 windows11wifi总掉线的解决方法
  8. ssh系统环境搭建步骤
  9. b丅151组成的充电器电路_宜家LIVBOJ 无线充电器拆解,这设计一目了然
  10. python中yield讲解_「技术」如何深入理解Python中的 yield?