📄 r5rs-z-h-10.html
字号:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><!-- Generated from TeX source by tex2page, v 4o4, (c) Dorai Sitaram, http://www.cs.rice.edu/~dorai/tex2page --><head><title>Revised^5 Report on the Algorithmic Language Scheme</title><link rel="stylesheet" type="text/css" href="r5rs-Z-C.css" title=default><meta name=robots content="noindex,follow"></head><body><p><div class=navigation>[Go to <span><a href="r5rs.html">first</a>, <a href="r5rs-Z-H-9.html">previous</a></span><span>, <a href="r5rs-Z-H-11.html">next</a></span> page<span>; </span><span><a href="r5rs-Z-H-2.html#%_toc_start">contents</a></span><span><span>; </span><a href="r5rs-Z-H-15.html#%_index_start">index</a></span>]</div><p><a name="%_chap_7"></a><h1 class=chapter><div class=chapterheading><a href="r5rs-Z-H-2.html#%_toc_%_chap_7">Chapter 7</a></div><p><a href="r5rs-Z-H-2.html#%_toc_%_chap_7">Formal syntax and semantics</a></h1><p><p>This chapter provides formal descriptions of what has already beendescribed informally in previous chapters of this report.<p><p><a name="%_sec_7.1"></a><h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.1">7.1 Formal syntax</a></h2><p><p>This section provides a formal syntax for Scheme written in an extendedBNF.<p>All spaces in the grammar are for legibility. Case is insignificant;for example, <tt>#x1A</tt> and <tt>#X1a</tt> are equivalent. <empty>stands for the empty string.<p>The following extensions to BNF are used to make the description moreconcise: <thing>* means zero or more occurrences of<thing>; and <thing><sup>+</sup> means at least one<thing>.<p><a name="%_sec_7.1.1"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.1.1">7.1.1 Lexical structure</a></h3><p>This section describes how individual tokens<a name="%_idx_636"></a> (identifiers,numbers, etc.) are formed from sequences of characters. The followingsections describe how expressions and programs are formed from sequencesof tokens.<p><Intertoken space> may occur on either side of any token, but notwithin a token.<p>Tokens which require implicit termination (identifiers, numbers,characters, and dot) may be terminated by any <delimiter>, but notnecessarily by anything else.<p>The following five characters are reserved for future extensions to thelanguage: <tt><code class=verbatim>[</code> <code class=verbatim>]</code> <code class=verbatim>{</code> <code class=verbatim>}</code> <code class=verbatim>|</code></tt><p><p><div align=left><img src="r5rs-Z-G-2.gif" border="0"></div><p><p><p><p><div align=left><img src="r5rs-Z-G-3.gif" border="0"></div><p><p><p><p><div align=left><img src="r5rs-Z-G-4.gif" border="0"></div><p><p>The following rules for <num <em>R</em>>, <complex <em>R</em>>, <real<em>R</em>>, <ureal <em>R</em>>, <uinteger <em>R</em>>, and <prefix <em>R</em>>should be replicated for <em>R</em> = 2, 8, 10,and 16. There are no rules for <decimal 2>, <decimal8>, and <decimal 16>, which means that numbers containingdecimal points or exponents must be in decimal radix.<p><p><div align=left><img src="r5rs-Z-G-5.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-6.gif" border="0"></div><p><p><p><a name="%_sec_7.1.2"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.1.2">7.1.2 External representations</a></h3><p><p><Datum> is what the <tt>read</tt> procedure (section <a href="r5rs-Z-H-9.html#%_sec_6.6.2">6.6.2</a>)successfully parses. Note that any string that parses as an<expression> will also parse as a <datum>. <p><p><div align=left><img src="r5rs-Z-G-7.gif" border="0"></div><p><p><a name="%_sec_7.1.3"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.1.3">7.1.3 Expressions</a></h3><p><p><div align=left><img src="r5rs-Z-G-8.gif" border="0"></div><p><p><a name="%_sec_7.1.4"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.1.4">7.1.4 Quasiquotations</a></h3><p>The following grammar for quasiquote expressions is not context-free.It is presented as a recipe for generating an infinite number ofproduction rules. Imagine a copy of the following rules for <em>D</em> = 1, 2,3, <tt>...</tt>. <em>D</em> keeps track of the nesting depth.<p><p><div align=left><img src="r5rs-Z-G-9.gif" border="0"></div><p><p>In <quasiquotation>s, a <list qq template <em>D</em>> can sometimesbe confused with either an <unquotation <em>D</em>> or a <splicingunquotation <em>D</em>>. The interpretation as an<unquotation> or <splicingunquotation <em>D</em>> takes precedence.<p><a name="%_sec_7.1.5"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.1.5">7.1.5 Transformers</a></h3><p><p><div align=left><img src="r5rs-Z-G-10.gif" border="0"></div><p><p><a name="%_sec_7.1.6"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.1.6">7.1.6 Programs and definitions</a></h3><p><p><div align=left><img src="r5rs-Z-G-11.gif" border="0"></div><p> <p><a name="%_sec_7.2"></a><h2><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.2">7.2 Formal semantics</a></h2><p><p><p><p>This section provides a formal denotational semantics for the primitiveexpressions of Scheme and selected built-in procedures. The conceptsand notation used here are described in [<a href="r5rs-Z-H-14.html#%_sec_7.3">29</a>]; the notation issummarized below:<p><p><div align=left><img src="r5rs-Z-G-12.gif" border="0"></div><p><p>The reason that expression continuations take sequences of values insteadof single values is to simplify the formal treatment of procedure callsand multiple return values.<p>The boolean flag associated with pairs, vectors, and strings will be truefor mutable objects and false for immutable objects.<p>The order of evaluation within a call is unspecified. We mimic thathere by applying arbitrary permutations <i>permute</i> and <i>unpermute</i>, which must be inverses, to the arguments in a call beforeand after they are evaluated. This is not quite right since it suggests,incorrectly, that the order of evaluation is constant throughout a program (forany given number of arguments), but it is a closer approximation to the intendedsemantics than a left-to-right evaluation would be.<p>The storage allocator <i>new</i> is implementation-dependent, but it mustobey the following axiom: if <i>new</i> <img src="r5rs-Z-G-D-2.gif" border="0"> <img src="r5rs-Z-G-D-4.gif" border="0"> <tt><em>L</em></tt>, then<img src="r5rs-Z-G-D-2.gif" border="0"> (<i>new</i> <img src="r5rs-Z-G-D-2.gif" border="0"> | <tt><em>L</em></tt>)<img src="r5rs-Z-G-D-7.gif" border="0"> 2 = <i><em>f</em><em>a</em><em>l</em><em>s</em><em>e</em></i>.<p><p>The definition of <img src="r5rs-Z-G-D-5.gif" border="0"> is omitted because an accurate definition of<img src="r5rs-Z-G-D-5.gif" border="0"> would complicate the semantics without being very interesting.<p>If P is a program in which all variables are defined before beingreferenced or assigned, then the meaning of P is<p><div align=left><img src="r5rs-Z-G-13.gif" border="0"></div><p>where I* is the sequence of variables defined in P, P'is the sequence of expressions obtained by replacing every definitionin P by an assignment, <undefined> is an expression that evaluatesto <i>undefined</i>, and<img src="r5rs-Z-G-D-6.gif" border="0"> is the semantic function that assigns meaning to expressions.<p><p><a name="%_sec_7.2.1"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.2.1">7.2.1 Abstract syntax</a></h3><p><p><p><div align=left><img src="r5rs-Z-G-14.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-15.gif" border="0"></div><p><p><a name="%_sec_7.2.2"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.2.2">7.2.2 Domain equations</a></h3><p><p><div align=left><img src="r5rs-Z-G-16.gif" border="0"></div><p><p><a name="%_sec_7.2.3"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_7.2.3">7.2.3 Semantic functions</a></h3><p><p><p><div align=left><img src="r5rs-Z-G-17.gif" border="0"></div><p><p><p><p><p><p><p>Definition of <img src="r5rs-Z-G-D-5.gif" border="0"> deliberately omitted.<p><p><div align=left><img src="r5rs-Z-G-18.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-19.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-20.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-21.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-22.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-23.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-24.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-25.gif" border="0"></div><p><p>Here and elsewhere, any expressed value other than <i>undefined</i> maybe used in place of <i>unspecified</i>.<p><p><div align=left><img src="r5rs-Z-G-26.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-27.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-28.gif" border="0"></div><p><p><p><div align=left><img src="r5rs-Z-G-29.gif" border="0"></div><p><p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -