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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Expressions</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-4-3-3.html">Previous</A> <A HREF="AA-4-5.html">Next</A></P>
<HR>
<H1> 4.4 Expressions</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2440"></A>An <I>expression</I> is a
formula that defines the computation or retrieval of a value. In this
International Standard, the term ``expression'' refers to a construct
of the syntactic category <FONT FACE="Arial, Helvetica">expression</FONT>
or of any of the other five syntactic categories defined below. <A NAME="I2441"></A><A NAME="I2442"></A><A NAME="I2443"></A><A NAME="I2444"></A><A NAME="I2445"></A><A NAME="I2446"></A><A NAME="I2447"></A><A NAME="I2448"></A><A NAME="I2449"></A><A NAME="I2450"></A><A NAME="I2451"></A><A NAME="I2452"></A><A NAME="I2453"></A><A NAME="I2454"></A><A NAME="I2455"></A><A NAME="I2456"></A><A NAME="I2457"></A><A NAME="I2458"></A><A NAME="I2459"></A><A NAME="I2460"></A><A NAME="I2461"></A><A NAME="I2462"></A><A NAME="I2463"></A><A NAME="I2464"></A><A NAME="I2465"></A><A NAME="I2466"></A><A NAME="I2467"></A><A NAME="I2468"></A><A NAME="I2469"></A><A NAME="I2470"></A><A NAME="I2471"></A><A NAME="I2472"></A><A NAME="I2473"></A><A NAME="I2474"></A><A NAME="I2475"></A><A NAME="I2476"></A><A NAME="I2477"></A><A NAME="I2478"></A><A NAME="I2479"></A><A NAME="I2480"></A><A NAME="I2481"></A><A NAME="I2482"></A><A NAME="I2483"></A><A NAME="I2484"></A><A NAME="I2485"></A><A NAME="I2486"></A><A NAME="I2487"></A><A NAME="I2488"></A><A NAME="I2489"></A><A NAME="I2490"></A><A NAME="I2491"></A><A NAME="I2492"></A><A NAME="I2493"></A><A NAME="I2494"></A><A NAME="I2495"></A><A NAME="I2496"></A><A NAME="I2497"></A><A NAME="I2498"></A><A NAME="I2499"></A><A NAME="I2500"></A><A NAME="I2501"></A><A NAME="I2502"></A><A NAME="I2503"></A><A NAME="I2504"></A><A NAME="I2505"></A><A NAME="I2506"></A><A NAME="I2507"></A><A NAME="I2508"></A><A NAME="I2509"></A><A NAME="I2510"></A><A NAME="I2511"></A><A NAME="I2512"></A></DIV>
<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">expression<A NAME="I2513"></A>
::= </FONT><BR>
<A NAME="I2514"></A><FONT FACE="Arial, Helvetica">relation</FONT> {<B>and</B> <A NAME="I2515"></A><FONT FACE="Arial, Helvetica">relation</FONT>} | <A NAME="I2516"></A><FONT FACE="Arial, Helvetica">relation</FONT> {<B>and</B> <B>then</B> <A NAME="I2517"></A><FONT FACE="Arial, Helvetica">relation</FONT>}<BR>
| <A NAME="I2518"></A><FONT FACE="Arial, Helvetica">relation</FONT> {<B>or</B> <A NAME="I2519"></A><FONT FACE="Arial, Helvetica">relation</FONT>} | <A NAME="I2520"></A><FONT FACE="Arial, Helvetica">relation</FONT> {<B>or</B> <B>else</B> <A NAME="I2521"></A><FONT FACE="Arial, Helvetica">relation</FONT>}<BR>
| <A NAME="I2522"></A><FONT FACE="Arial, Helvetica">relation</FONT> {<B>xor</B> <A NAME="I2523"></A><FONT FACE="Arial, Helvetica">relation</FONT>}</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">relation<A NAME="I2524"></A>
::= </FONT><BR>
<A NAME="I2525"></A><FONT FACE="Arial, Helvetica">simple_expression</FONT> [<A NAME="I2526"></A><FONT FACE="Arial, Helvetica">relational_operator</FONT> <A NAME="I2527"></A><FONT FACE="Arial, Helvetica">simple_expression</FONT>]<BR>
| <A NAME="I2528"></A><FONT FACE="Arial, Helvetica">simple_expression</FONT> [<B>not</B>] <B>in</B> <A NAME="I2529"></A><FONT FACE="Arial, Helvetica">range</FONT><BR>
| <A NAME="I2530"></A><FONT FACE="Arial, Helvetica">simple_expression</FONT> [<B>not</B>] <B>in</B> <A NAME="I2531"></A><FONT FACE="Arial, Helvetica">subtype_mark</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">simple_expression<A NAME="I2532"></A>
::= </FONT>[<A NAME="I2533"></A><FONT FACE="Arial, Helvetica">unary_adding_operator</FONT>] <A NAME="I2534"></A><FONT FACE="Arial, Helvetica">term</FONT> {<A NAME="I2535"></A><FONT FACE="Arial, Helvetica">binary_adding_operator</FONT> <A NAME="I2536"></A><FONT FACE="Arial, Helvetica">term</FONT>}</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">term<A NAME="I2537"></A>
::= </FONT><A NAME="I2538"></A><FONT FACE="Arial, Helvetica">factor</FONT> {<A NAME="I2539"></A><FONT FACE="Arial, Helvetica">multiplying_operator</FONT> <A NAME="I2540"></A><FONT FACE="Arial, Helvetica">factor</FONT>}</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">factor<A NAME="I2541"></A>
::= </FONT><A NAME="I2542"></A><FONT FACE="Arial, Helvetica">primary</FONT> [** <A NAME="I2543"></A><FONT FACE="Arial, Helvetica">primary</FONT>] | <B>abs</B> <A NAME="I2544"></A><FONT FACE="Arial, Helvetica">primary</FONT> | <B>not</B> <A NAME="I2545"></A><FONT FACE="Arial, Helvetica">primary</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">primary<A NAME="I2546"></A>
::= </FONT><BR>
<A NAME="I2547"></A><FONT FACE="Arial, Helvetica">numeric_literal</FONT> | <B>null</B> | <A NAME="I2548"></A><FONT FACE="Arial, Helvetica">string_literal</FONT> | <A NAME="I2549"></A><FONT FACE="Arial, Helvetica">aggregate</FONT><BR>
| <A NAME="I2550"></A><FONT FACE="Arial, Helvetica">name</FONT> | <A NAME="I2551"></A><FONT FACE="Arial, Helvetica">qualified_expression</FONT> | <A NAME="I2552"></A><FONT FACE="Arial, Helvetica">allocator</FONT> | (<A NAME="I2553"></A><FONT FACE="Arial, Helvetica">expression</FONT>)</DIV>
<H4 ALIGN=CENTER>Name Resolution Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Normal"> A <FONT FACE="Arial, Helvetica">name</FONT> used
as a <FONT FACE="Arial, Helvetica">primary</FONT> shall resolve to denote
an object or a value. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>This replaces
RM83-4.4(3). We don't need to mention named numbers explicitly, because
the name of a named number denotes a value. We don't need to mention
attributes explicitly, because attributes now denote (rather than yield)
values in general. Also, the new wording allows attributes that denote
objects, which should always have been allowed (in case the implementation
chose to have such a thing). </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>It might seem odd
that this is an overload resolution rule, but it is relevant during overload
resolution. For example, it helps ensure that a <FONT FACE="Arial, Helvetica">primary</FONT>
that consists of only the identifier of a parameterless function is interpreted
as a <FONT FACE="Arial, Helvetica">function_call</FONT> rather than directly
as a <FONT FACE="Arial, Helvetica">direct_name</FONT>. </FONT></DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="Normal"> Each expression has a type; it specifies the computation
or retrieval of a value of that type. </DIV>
<H4 ALIGN=CENTER>Dynamic Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2554"></A>The value of a <FONT FACE="Arial, Helvetica">primary</FONT>
that is a <FONT FACE="Arial, Helvetica">name</FONT> denoting an object
is the value of the object. </DIV>
<H4 ALIGN=CENTER>Implementation Permissions</H4>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2555"></A><A NAME="I2556"></A><A NAME="I2557"></A>For
the evaluation of a <FONT FACE="Arial, Helvetica">primary</FONT> that
is a <FONT FACE="Arial, Helvetica">name</FONT> denoting an object of
an unconstrained numeric subtype, if the value of the object is outside
the base range of its type, the implementation may either raise Constraint_Error
or return the value of the object. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This means
that if extra-range intermediates are used to hold the value of an object
of an unconstrained numeric subtype, a Constraint_Error can be raised
on a read of the object, rather than only on an assignment to it. Similarly,
it means that computing the value of an object of such a subtype can
be deferred until the first read of the object (presuming no side-effects
other than failing an Overflow_Check are possible). This permission is
over and above that provided by clause <A HREF="AA-11-6.html">11.6</A>,
since this allows the Constraint_Error to move to a different handler.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This permission
is intended to allow extra-range registers to be used efficiently to
hold parameters and local variables, even if they might need to be transferred
into smaller registers for performing certain predefined operations.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>There is no
need to mention other kinds of <FONT FACE="Arial, Helvetica">primary</FONT>s,
since any Constraint_Error to be raised can be ``charged'' to the evaluation
of the particular kind of <FONT FACE="Arial, Helvetica">primary</FONT>.
</FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Examples of
primaries:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Examples" Style="margin-bottom: 0.9em"><TT>4.0 <I>-- real literal</I><BR>
Pi <I>-- named number</I><BR>
(1 .. 10 => 0) <I>-- array aggregate</I><BR>
Sum <I>-- variable</I><BR>
Integer'Last <I>-- attribute</I><BR>
Sine(X) <I>-- function call</I><BR>
Color'(Blue) <I>-- qualified expression</I><BR>
Real(M*N) <I>-- conversion</I><BR>
(Line_Count + 10) <I>-- parenthesized expression </I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Examples of
expressions:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Examples"><TT>Volume <I>-- primary</I><BR>
<B>not</B> Destroyed <I>-- factor</I><BR>
2*Line_Count <I>-- term </I><BR>
-4.0 <I>-- simple expression</I><BR>
-4.0 + A <I>-- simple expression</I><BR>
B**2 - 4.0*A*C <I>-- simple expression</I><BR>
Password(1 .. 3) = "Bwv" <I>-- relation</I><BR>
Count <B>in</B> Small_Int <I>-- relation</I><BR>
Count <B>not</B> <B>in</B> Small_Int <I>-- relation</I><BR>
Index = 0 <B>or</B> Item_Hit <I>-- expression</I><BR>
(Cold <B>and</B> Sunny) <B>or</B> Warm <I>-- expression (parentheses are required)</I><BR>
A**(B**C) <I>-- expression (parentheses are required)</I></TT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>15.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I2558"></A>In Ada 83,
<B>out</B> parameters and their nondiscriminant subcomponents are not
allowed as <FONT FACE="Arial, Helvetica">primaries</FONT>. These restrictions
are eliminated in Ada 95.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>In various contexts throughout
the language where Ada 83 syntax rules had <FONT FACE="Arial, Helvetica">simple_expression</FONT>,
the corresponding Ada 95 syntax rule has <FONT FACE="Arial, Helvetica">expression</FONT>
instead. This reflects the inclusion of modular integer types, which
makes the logical operators "<B>and</B>", "<B>or</B>",
and "<B>xor</B>" more useful in expressions of an integer type.
Requiring parentheses to use these operators in such contexts seemed
unnecessary and potentially confusing. Note that the bounds of a <FONT FACE="Arial, Helvetica">range</FONT>
still have to be specified by <FONT FACE="Arial, Helvetica">simple_expression</FONT>s,
since otherwise <FONT FACE="Arial, Helvetica">expression</FONT>s involving
membership tests might be ambiguous. Essentially, the operation ".."
is of higher precedence than the logical operators, and hence uses of
logical operators still have to be parenthesized when used in a bound
of a range. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-4-3-3.html">Previous</A> <A HREF="AA-4-5.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|