1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Method of Description and Syntax Notation</TITLE>
<META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
<META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
<STYLE type="text/css">
DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
TT {font-family: "Courier New", monospace}
DT {display: compact}
DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Index {font-family: "Times New Roman", Times, serif}
DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left: 10.0em; margin-bottom: 0.6em}
DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 15.0em; margin-bottom: 0.6em}
UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
DD.Hanging {margin-left: 6.0em}
DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.IndentedHanging {margin-left: 2.0em}
DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.HangingInBulleted {margin-left: 4.0em}
DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallHanging {margin-left: 7.5em}
DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallIndentedHanging {margin-left: 2.0em}
DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallHangingInBulleted {margin-left: 5.0em}
DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.Enumerated {margin-left: 2.0em}
DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallEnumerated {margin-left: 2.5em}
DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-1-1-3.html">Previous</A> <A HREF="AA-1-1-5.html">Next</A></P>
<HR>
<H1> 1.1.4 Method of Description and Syntax Notation</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> The form of an Ada program is described by means
of a context-free syntax together with context-dependent requirements
expressed by narrative rules.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal"> The meaning of Ada programs is described by means
of narrative rules defining both the effects of each construct and the
composition rules for constructs.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I1068"></A><A NAME="I1069"></A><A NAME="I1070"></A><A NAME="I1071"></A><A NAME="I1072"></A>The
context-free syntax of the language is described using a simple variant
of Backus-Naur Form. In particular: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC>Lower case words in a sans-serif font, some containing
embedded underlines, are used to denote syntactic categories, for example:
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="CodeIndented"><FONT FACE="Arial, Helvetica">case_statement</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC>Boldface words are used to denote reserved words, for example:
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="CodeIndented"><B>array</B></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC>Square brackets enclose optional items. Thus the two following
rules are equivalent. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="CodeIndented"><FONT FACE="Arial, Helvetica">return_statement</FONT> ::= <B>return</B> [<FONT FACE="Arial, Helvetica">expression</FONT>];<BR>
<FONT FACE="Arial, Helvetica">return_statement</FONT> ::= <B>return</B>; | <B>return</B> <FONT FACE="Arial, Helvetica">expression</FONT>;</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC>Curly brackets enclose a repeated item. The item may appear
zero or more times; the repetitions occur from left to right as with
an equivalent left-recursive rule. Thus the two following rules are equivalent.
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="CodeIndented"><FONT FACE="Arial, Helvetica">term</FONT> ::= <FONT FACE="Arial, Helvetica">factor</FONT> {<FONT FACE="Arial, Helvetica">multiplying_operator</FONT> <FONT FACE="Arial, Helvetica">factor</FONT>}<BR>
<FONT FACE="Arial, Helvetica">term</FONT> ::= <FONT FACE="Arial, Helvetica">factor</FONT> | <FONT FACE="Arial, Helvetica">term</FONT> <FONT FACE="Arial, Helvetica">multiplying_operator</FONT> <FONT FACE="Arial, Helvetica">factor</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC>A vertical line separates alternative items unless it occurs
immediately after an opening curly bracket, in which case it stands for
itself: </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="CodeIndented"><FONT FACE="Arial, Helvetica">constraint</FONT> ::= <FONT FACE="Arial, Helvetica">scalar_constraint</FONT> | <FONT FACE="Arial, Helvetica">composite_constraint</FONT><BR>
<FONT FACE="Arial, Helvetica">discrete_choice_list</FONT> ::= <FONT FACE="Arial, Helvetica">discrete_choice</FONT> {| <FONT FACE="Arial, Helvetica">discrete_choice</FONT>}</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I1073"></A>If the name of any syntactic category
starts with an italicized part, it is equivalent to the category name
without the italicized part. The italicized part is intended to convey
some semantic information. For example <I>subtype_</I><FONT FACE="Arial, Helvetica">name</FONT>
and <I>task_</I><FONT FACE="Arial, Helvetica">name</FONT> are both equivalent
to <FONT FACE="Arial, Helvetica">name</FONT> alone. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>14.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B><A NAME="I1074"></A><A NAME="I1075"></A><A NAME="I1076"></A><A NAME="I1077"></A>The
grammar given in the RM95 is not LR(1). In fact, it is ambiguous; the
ambiguities are resolved by the overload resolution rules (see <A HREF="AA-8-6.html">8.6</A>).</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We often use ``if'' to mean ``if
and only if'' in definitions. For example, if we define ``photogenic''
by saying, ``A type is photogenic if it has the following properties...,''
we mean that a type is photogenic if <I>and only if</I> it has those
properties. It is usually clear from the context, and adding the ``and
only if'' seems too cumbersome.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>When we say, for example, ``a
<FONT FACE="Arial, Helvetica">declarative_item</FONT> of a <FONT FACE="Arial, Helvetica">declarative_part</FONT>'',
we are talking about a <FONT FACE="Arial, Helvetica">declarative_item</FONT>
immediately within that <FONT FACE="Arial, Helvetica">declarative_part</FONT>.
When we say ``a <FONT FACE="Arial, Helvetica">declarative_item</FONT>
in, or within, a <FONT FACE="Arial, Helvetica">declarative_part</FONT>'',
we are talking about a <FONT FACE="Arial, Helvetica">declarative_item</FONT>
anywhere in the <FONT FACE="Arial, Helvetica">declarative_part</FONT>,
possibly deeply nested within other <FONT FACE="Arial, Helvetica">declarative_part</FONT>s.
(This notation doesn't work very well for <FONT FACE="Arial, Helvetica">name</FONT>s,
since the name ``of'' something also has another meaning.)</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>When we refer to the name of a
language-defined entity (for example, Duration), we mean the language-defined
entity even in programs where the declaration of the language-defined
entity is hidden by another declaration. For example, when we say that
the expected type for the <FONT FACE="Arial, Helvetica">expression</FONT>
of a <FONT FACE="Arial, Helvetica">delay_relative_statement</FONT> is
Duration, we mean the language-defined type Duration that is declared
in Standard, not some type Duration the user might have declared. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Wide"> <A NAME="I1078"></A>A <I>syntactic category</I>
is a nonterminal in the grammar defined in BNF under ``Syntax.'' Names
of syntactic categories are set in a different font, <FONT FACE="Arial, Helvetica">like_this</FONT>.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1079"></A>A <I>construct</I> is a piece
of text (explicit or implicit) that is an instance of a syntactic category
defined under ``Syntax.'' </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>For example,
an <FONT FACE="Arial, Helvetica">expression</FONT> is a construct. A
declaration is a construct, whereas the thing declared by a declaration
is an ``entity.'' </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>``Explicit''
and ``implicit'' don't mean exactly what you might think they mean: The
text of an instance of a generic is considered explicit, even though
it does not appear explicitly (in the non-technical sense) in the program
text, and even though its meaning is not defined entirely in terms of
that text. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1080"></A>A <I>constituent</I> of a
construct is the construct itself, or any construct appearing within
it.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<DIV Class="Normal"> <A NAME="I1081"></A>Whenever the run-time semantics
defines certain actions to happen in an <I>arbitrary order</I>, this
means that the implementation shall arrange for these actions to occur
in a way that is equivalent to some sequential order, following the rules
that result from that sequential order. When evaluations are defined
to happen in an arbitrary order, with conversion of the results to some
subtypes, or with some run-time checks, the evaluations, conversions,
and checks may be arbitrarily interspersed, so long as each expression
is evaluated before converting or checking its value. <A NAME="I1082"></A><A NAME="I1083"></A>[Note
that the effect of a program can depend on the order chosen by the implementation.
This can happen, for example, if two actual parameters of a given call
have side effects.] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Programs will
be more portable if their external effect does not depend on the particular
order chosen by an implementation. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Additional
reordering permissions are given in <A HREF="AA-11-6.html">11.6</A>,
``<A HREF="AA-11-6.html">Exceptions and Optimization</A>''.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>There is no requirement that the
implementation always choose the same order in a given kind of situation.
In fact, the implementation is allowed to choose a different order for
two different executions of the same construct. However, we expect most
implementations will behave in a relatively predictable manner in most
situations. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>The ``sequential
order'' wording is intended to allow the programmer to rely on ``benign''
side effects. For example, if F is a function that returns a unique integer
by incrementing some global and returning the result, a call such as
P(F, F) is OK if the programmer cares only that the two results of F
are unique; the two calls of F cannot be executed in parallel, unless
the compiler can prove that parallel execution is equivalent to some
sequential order. </FONT></DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>3 The syntax rules describing
structured constructs are presented in a form that corresponds to the
recommended paragraphing. For example, an <FONT FACE="Arial, Helvetica">if_statement</FONT>
is defined as: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<DIV Class="Examples"><TT><FONT FACE="Arial, Helvetica">if_statement</FONT> ::=<BR>
<B>if</B> <FONT FACE="Arial, Helvetica">condition</FONT> <B>then</B><BR>
<FONT FACE="Arial, Helvetica">sequence_of_statements</FONT><BR>
{<B>elsif</B> <FONT FACE="Arial, Helvetica">condition</FONT> <B>then</B><BR>
<FONT FACE="Arial, Helvetica">sequence_of_statements</FONT>}<BR>
[<B>else</B><BR>
<FONT FACE="Arial, Helvetica">sequence_of_statements</FONT>]<BR>
<B>end if</B>;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>4 The line breaks and indentation
in the syntax rules indicate the recommended line breaks and indentation
in the corresponding constructs. The preferred places for other line
breaks are after semicolons. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-1-1-3.html">Previous</A> <A HREF="AA-1-1-5.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|