免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4266 | 回复: 0
打印 上一主题 下一主题

Python 3.1.1 中英文对照版语言参考手册 - 介绍 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-29 17:06 |只看该作者 |倒序浏览

                                                    一二月之前,参加了HelloGcc的Workshop
2009,激起了对编译器的兴趣。思来想去,如果想上手写个简单的编译器、解释器之类的话,选择一个简单的语言应该是上选,这样,在我熟悉的语言中就锁定
Python了,于是就有了更新Python语言参考手册的想法。即使没有达成写编译器/解释器的宏愿,也算留下了些脚印。
    几年之前,初学Python之时就曾经在linuxforum.net上与Limodou和和Smile一起翻译过Python 2.3的参考手册,当时的目的是学习Python。现在回首看看之前的成果,我翻译那部分真是惨不忍睹~ 汲取上次的教训,这次不直接从HTML格式翻译了,而是选择了源代码里的reStructedText格式的文件,上手时虽然有些别扭,翻译几段就进入状态了。选择reStructedText格式的好处是便于跟上新版本Python的变动。
    此次更新并不是从零开始的工作,是上次翻译成果的继续,所以,这里仍然要感謝limodou和smile的之前做的工作。
    翻译进度如下:除了“简单语句”外,都已经翻译完成,其他章节正在校对中。   

    最后,欢迎各位来找茬的,我会及时修正这些茬子的。1. 介绍(Introduction)
This reference manual describes the Python programming language. It is not
intended as a tutorial.
本参考手册描述了Python程序设计语言, 但本文档并不是新手手册。
While I am trying to be as precise as possible, I chose to use English rather
than formal specifications for everything except syntax and lexical analysis.
This should make the document more understandable to the average reader, but
will leave room for ambiguities. Consequently, if you were coming from Mars and
tried to re-implement Python from this document alone, you might have to guess
things and in fact you would probably end up implementing quite a different
language. On the other hand, if you are using Python and wonder what the precise
rules about a particular area of the language are, you should definitely be able
to find them here. If you would like to see a more formal definition of the
language, maybe you could volunteer your time — or invent a cloning machine
:-).
虽然本文档试图做到尽量精确, 但除了语法分析和词法分析部分之外,我们还是选择了用英语(中文)而不是形式化的表达方法,
对于大多部读者来说这样更具可读性,
但却有可能存在歧义。因此,如果你对Python很陌生,并且想只凭这篇文档就重新实现Python的话,你恐怕必须得猜测补充一些细节,甚至可能你会以
实现一门完全不同的语言而告终;另一方面,如果你在使用Python并且想了解某个细节的精确规则,你应该可以在这里清楚地找到它。如果你想获得语言的更
详细的形式化定义,可能就要自己搞了 —— 或者发明一个克隆机:-)。
It is dangerous to add too many implementation details to a language reference
document — the implementation may change, and other implementations of the
same language may work differently.  On the other hand, CPython is the one
Python implementation in widespread use (although alternate implementations
continue to gain support), and its particular quirks are sometimes worth being
mentioned, especially where the implementation imposes additional limitations.
Therefore, you’ll find short “implementation notes” sprinkled throughout the
text.
在语言参考文档中涉及太多实现细节并不是个明智决定——实现本身可能会变化,并且不同实现的工作方式可能互不相同。另一方面,
CPython作为目前得到广泛使用的一个实现(不过,其他实现也已经得到了持续的支持),它的一些微妙之处还是值得特别注意的。尤其是,某个实现可能会
引入了额外限制,因此,你在本文档中会找到”实现注意”的标记。
Every Python implementation comes with a number of built-in and standard
modules.  These are documented in
The Python Standard Library
.  A few built-in modules
are mentioned when they interact in a significant way with the language
definition.
每个Python实现都提供了大量的内置和标准模块, 它们的介绍可以在
The Python Standard Library
中找到,但这里也提到了少量与语言定义密切相关的内置模块。
1.1. 其他实现(Alternate Implementations)
Though there is one Python implementation which is by far the most popular,
there are some alternate implementations which are of particular interest to
different audiences.
虽然我们已经有一个最为流行的Python实现了,但某些读者对其它实现也会有特别兴趣:
Known implementations include:
已知的实现包括:
CPythonThis is the original and most-maintained implementation of Python, written in C.
New language features generally appear here first.
这是Python的最初实现,同时也是得到最好维护的C实现。新的语言特性一般首先出现在这个实现中。
JythonPython implemented in Java.  This implementation can be used as a scripting
language for Java applications, or can be used to create applications using the
Java class libraries.  It is also often used to create tests for Java libraries.
More information can be found at
the Jython website
.
Python语言的Java实现,它可以作为Java应用的脚本语言,或者使用Java类库创建Python应用程序。它也经常用于构造Java程序库的测试用例。关于本实现的更多介绍可以在这里找到
Jython主页

Python for .NETThis implementation actually uses the CPython implementation, but is a managed
.NET application and makes .NET libraries available.  It was created by Brian
Lloyd.  For more information, see the
Python for .NET home page
.
这个实现内部实际上使用的是CPython的实现,但它是一个托管的.NET应用,并且可以利用.NET程序库。本实现由Brian Lloyd创建,更多信息可以在它的主页找到
Python for .NET 主页

IronPythonAn alternate Python for .NET.  Unlike Python.NET, this is a complete Python
implementation that generates IL, and compiles Python code directly to .NET
assemblies.  It was created by Jim Hugunin, the original creator of Jython.  For
more information, see
the IronPython website
.
另一个.NET上的Python实现,与上者不同,这是一个可以生成IL,并把Python代码编译成.NET assemblies的全新Python实现。它由Jython的最初作者Jim Hugunin实现,更多信息可以在这里找到:
IronPython主页

PyPyAn implementation of Python written in Python; even the bytecode interpreter is
written in Python.  This is executed using CPython as the underlying
interpreter.  One of the goals of the project is to encourage experimentation
with the language itself by making it easier to modify the interpreter (since it
is written in Python).  Additional information is available on the PyPy
project’s home page.
这是一个用Python实现的Python,甚至字节码解释器也是用Python实现的,它使用CPython作为底层的解释器。这个项目的目的之一是通过创建一个易于修改(因为由Python写成)的解释器以鼓励对语言本身的探索。额外的信息可以在这里找到:
PyPy的项目主页

Each of these implementations varies in some way from the language as documented
in this manual, or introduces specific information beyond what’s covered in the
standard Python documentation.  Please refer to the implementation-specific
documentation to determine what else you need to know about the specific
implementation you’re using.
以上的各种实现与本文档之间都存在着的一定差异,或者在标准Python特性中引入了特别的内容。关于具体实现的内容,你可以参考它们的文档。
1.2. 记法(Notation)
The descriptions of lexical analysis and syntax use a modified BNF grammar
notation.  This uses the following style of definition:
在词法和语法分析的描述中,我们使用一种修改过的BNF语法描述方式,它使用以下风格的定义格式:
name      ::=  
lc_letter
(
lc_letter
| "_")*
lc_letter ::=  "a"..."z"
The first line says that a name is an lc_letter followed by a sequence
of zero or more lc_letters and underscores.  An lc_letter in turn is
any of the single characters 'a' through 'z'.  (This rule is actually
adhered to for the names defined in lexical and grammar rules in this document.)
第一行说明 名字(name) 为 lc letter 后跟随零个以上(包括零个) lc letter 或下划线的序列。 lc letter 是 a 至 z 中任意一个字符。(这条规则实际上贯穿于本文档中所有词法和语法规则中的名字定义)。
Each rule begins with a name (which is the name defined by the rule) and
::=.  A vertical bar (|) is used to separate alternatives; it is the
least binding operator in this notation.  A star (*) means zero or more
repetitions of the preceding item; likewise, a plus (+) means one or more
repetitions, and a phrase enclosed in square brackets ([ ]) means zero or
one occurrences (in other words, the enclosed phrase is optional).  The *
and + operators bind as tightly as possible; parentheses are used for
grouping.  Literal strings are enclosed in quotes.  White space is only
meaningful to separate tokens. Rules are normally contained on a single line;
rules with many alternatives may be formatted alternatively with each line after
the first beginning with a vertical bar.
每个规则以一个名字(规则要定义的名字)和 ::= 为开始. 竖线( | )用于分隔“多选一项”,它是记法中结合性最弱的符号。星号( * )意味着前一项的零次或多次的重复;同样, 加号( + )意味着一次或多次的重复。在方括号( []
)中的内容意味着它可以出现零次或一次(也就是说它是可选的)。星号和加号与前面的项尽可能地紧密的结合,
小括号用于分组。字符串字面值(literal
strings)用引号括住,空白字符只用于分隔语言符号(token)。通常规则被包含在一行之中,有很多多选一项的规则也可以被格式化成多行的形式,
但后续行都会竖线开始.
In lexical definitions (as the example above), two more conventions are used:
Two literal characters separated by three dots mean a choice of any single
character in the given (inclusive) range of ASCII characters.  A phrase between
angular brackets () gives an informal description of the symbol
defined; e.g., this could be used to describe the notion of ‘control character’
if needed.
在词法定义中(如上面的例子)有两个惯例:用三个句点分隔的一对字符串字面值表示在给定ASCII字符范围内(包括边界值)任意一个字符。在尖括号(  )中的文字给出了所定义符号的非正式的说明,例如,这用在了需要说明”控制字符”记法的情况。
Even though the notation used is almost the same, there is a big difference
between the meaning of lexical and syntactic definitions: a lexical definition
operates on the individual characters of the input source, while a syntax
definition operates on the stream of tokens generated by the lexical analysis.
All uses of BNF in the next chapter (“Lexical Analysis”) are lexical
definitions; uses in subsequent chapters are syntactic definitions.
虽然两者的记法几乎完全相同,但词法定义和语法定义实际上存在着巨大的区别:词法定义是在输入源的单个字符上进行操作,而语法定义是在由词法分析生成的语言符号流上进行操作。在下节(”词法分析”)中使用的BNF都是词法定义,以后的章节中则语法定义。
               
               
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/42957/showart_2106772.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP