?? 1076_7.html
字號(hào):
<html>
<head>
<title>VHDL LRM- Introduction</title>
</head>
<body>
<h1><a name="7">Section 7</a></h1>
<a href="../../HTML/HOMEPG.HTM"><img src="HP.GIF" border=0></a>
<a href="1076_TOC.HTM"><img src="TOP.GIF" BORDER=0></a>
<a href="1076_6.HTM"><img src="LEFT.GIF" BORDER=0></a>
<a href="1076_8.HTM"><img src="RIGHT.GIF" BORDER=0></a>
<HR>
<h1>Expressions</h1>
<p>
<p>
<p>The rules applicable to the different forms of expression, and to their evaluation, are given in this section.
<h2><a name="7.1"> <a href = "1076_7.HTM#7.1"> 7.1 </a> Expressions</a></h2>
<p>An expression is a formula that defines the computation of a value.
<pre> expression ::=
relation { <b>and</b> relation }
| relation { <b>or</b> relation }
| relation { <b>xor</b> relation }
| relation [ <b>nand</b> relation ]
| relation [ <b>nor</b> relation ]
| relation { <b>xnor</b> relation }
relation ::=
shift_expression [ relational_operator shift_expression ]
shift_expression ::=
simple_expression [ shift_operator simple_expression ]
simple_expression ::=
[ sign ] term { adding_operator term }
term ::=
factor { multiplying_operator factor }
factor ::=
primary [ ** primary ]
| <b>abs</b> primary
| <b>not</b> primary
primary ::=
name
| literal
| aggregate
| function_call
| qualified_expression
| type_conversion
| allocator
| ( expression )
</pre>
<p>Each primary has a value and a type. The only names allowed as primaries are attributes that yield values and names denoting objects or values. In the case of names denoting objects, the value of the primary is the value of the object.
<p>The type of an expression depends only upon the types of its operands and on the operators applied; for an overloaded operand or operator, the determination of the operand type, or the identification of the overloaded operator, depends on the context (see <a href = "1076_10.HTM#10.5"> 10.5 </a> ). For each predefined operator, the operand and result types are given in the following clause.
<p>NOTE--The syntax for an expression involving logical operators allows a sequence of <b>and</b>, <b>or</b>, <b>xor</b>, or <b>xnor</b> operators (whether predefined or user-defined), since the corresponding predefined operations are associative. For the operators <b>nand</b> and <b>nor</b> (whether predefined or user-defined), however, such a sequence is not allowed, since the corresponding predefined operations are not associative.
<h2><a name="7.2"> <a href = "1076_7.HTM#7.2"> 7.2 </a> Operators</a></h2>
<p>The operators that may be used in expressions are defined below. Each operator belongs to a class of operators, all of which have the same precedence level;the classes of operators are listed in order of increasing precedence.
<table border="0">
<tr><td align="left" width="125">logical_operator<td align="center" width="50"><td align="center" width="50">::=<td align="center" width="50"><b>and</b><td align="center" width="50">|<td align="center" width="50"><b>or</b><td align="center" width="50">|<td align="center" width="50"><b>nand</b><td align="center" width="50">|<td align="center" width="50"><b>nor</b><td align="center" width="50">|<td align="center" width="50"><b>xor</b><td align="center" width="50">|<td align="center" width="50"><b>xnor</b></tr>
<tr><td align="left" width="125">relational_operator<td align="center" width="50"><td align="center" width="50">::=<td align="center" width="50">=<td align="center" width="50">|<td align="center" width="50">/=<td align="center" width="50">|<td align="center" width="50"><<td align="center" width="50">|<td align="center" width="50"><=<td align="center" width="50">|<td align="center" width="50">><td align="center" width="50">|<td align="center" width="50">>=</tr>
<tr><td align="left" width="125">shift_operator<td align="center" width="50"><td align="center" width="50">::=<td align="center" width="50"><b>sll</b><td align="center" width="50">|<td align="center" width="50"><b>srl</b><td align="center" width="50">|<td align="center" width="50"><b>sla</b><td align="center" width="50">|<td align="center" width="50"><b>sra</b><td align="center" width="50">|<td align="center" width="50"><b>rol</b><td align="center" width="50">|<td align="center" width="50"><b>ror</b></tr>
<tr><td align="left" width="125">adding_operator<td align="center" width="50"><td align="center" width="50">::=<td align="center" width="50">+<td align="center" width="50">|<td align="center" width="50">-<td align="center" width="50">|<td align="center" width="50">&<td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"></tr>
<tr><td align="left" width="125">sign<td align="center" width="50"><td align="center" width="50">::=<td align="center" width="50">+<td align="center" width="50">|<td align="center" width="50">-<td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"></tr>
<tr><td align="left" width="125">mutiplying_operator<td align="center" width="50"><td align="center" width="50">::=<td align="center" width="50">*<td align="center" width="50">|<td align="center" width="50">/<td align="center" width="50">|<td align="center" width="50"><b>mod</b><td align="center" width="50">|<td align="center" width="50"><b>rem</b><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"></tr>
<tr><td align="left" width="125">micellaneous_operator<td align="center" width="50"><td align="center" width="50">::=<td align="center" width="50">**<td align="center" width="50">|<td align="center" width="50"><b>abs</b><td align="center" width="50">|<td align="center" width="50"><b>not</b><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"><td align="center" width="50"></tr>
</table>
</center>
<p>Operators of higher precedence are associated with their operands before operators of lower precedence. Where the language allows a sequence of operators, operators with the same precedence level are associated with their operands in textual order, from left to right. The precedence of an operator is fixed and may not be changed by the user, but parentheses can be used to control the association of operators and operands.
<p>In general, operands in an expression are evaluated before being associated with operators. For certain operations, however, the right-hand operand is evaluated if and only if the left-hand operand has a certain value. These operations are called <i>short-circuit</i> operations. The logical operations <b>and</b>, <b>or</b>, <b>nand</b>, and <b>nor</b> defined for operands of types BIT and BOOLEAN are all short-circuit operations; furthermore, these are the only short-circuit operations.
<p>Every predefined operator is a pure function (see <a href = "1076_2.HTM#2.1"> 2.1 </a> ). No predefined operators have named formal parameters; therefore, named association (see <a href = "1076_4.HTM#4.3.2.2"> 4.3.2.2 </a> ) may not be used when invoking a predefined operation.
<h4>NOTES</h4>
<p>
<p>1--The predefined operators for the standard types are declared in package STANDARD as shown in <a href = "1076_14.HTM#14.2"> 14.2 </a> .
<p>2--The operator <b>not</b> is classified as a miscellaneous operator for the purposes of defining precedence, but is otherwise classified as a logical operator.
<h3><a name="7.2.1"> <a href = "1076_7.HTM#7.2.1"> 7.2.1 </a> Logical operators</a></h3>
<p>The logical operators <b>and</b>, <b>or</b>, <b>nand</b>, <b>nor</b>,<b>xor</b>, <b>xnor</b>, and <b>not</b> are defined for predefined types BIT and BOOLEAN. They are also defined for any one-dimensional array type whose element type is BIT or BOOLEAN. For the binary operators <b>and</b>,<b>or</b>, <b>nand</b>, <b>nor</b>, <b>xor</b>, and <b>xnor</b>, the operands must be of the same base type. Moreover, for the binary operators <b>and</b>,<b>or</b>, <b>nand</b>, <b>nor</b>, <b>xor</b>, and <b>xnor</b> defined on one-dimensional array types, the operands must be arrays of the same length,the operation is performed on matching elements of the arrays, and the result is an array with the same index range as the left operand. For the unary operator <b>not</b> defined on one-dimensional array types, the operation is performed on each element of the operand, and the result is an array with the same index range as the operand.
<p>The effects of the logical operators are defined in the following tables. The symbol T represents TRUE for type BOOLEAN, '1' for type BIT; the symbol F represents FALSE for type BOOLEAN, '0' for type BIT.<br><br>
<table border="0">
<tr><td align="center" width="25"><u>A</u><td align="center" width="25"><u>B</u><td align="center" width="75"><u>A <b>and</b> B</u><td align="center" width="25"><td align="center" width="25"><u>A</u><td align="center" width="25"><u>B</u><td align="center" width="75"><u>A <b>or</b> B</u><td align="center" width="25"><td align="center" width="25"><u>A</u><td align="center" width="25"><u>B</u><td align="center" width="75"><u>A <b>xor</b> B</u></tr>
<tr><td align="center" width="25"><td align="center" width="25"><td align="center" width="75"><td align="center" width="25"><td align="center" width="25"><td align="center" width="25"><td align="center" width="75"><td align="center" width="25"><td align="center" width="25"><td align="center" width="25"><td align="center" width="75"></tr>
<tr><td align="center" width="25">T<td align="center" width="25">T<td align="center" width="75">T<td align="center" width="25"><td align="center" width="25">T<td align="center" width="25">T<td align="center" width="75">T<td align="center" width="25"><td align="center" width="25">T<td align="center" width="25">T<td align="center" width="75">F</tr>
<tr><td align="center" width="25">T<td align="center" width="25">F<td align="center" width="75">F<td align="center" width="25"><td align="center" width="25">T<td align="center" width="25">F<td align="center" width="75">T<td align="center" width="25"><td align="center" width="25">T<td align="center" width="25">F<td align="center" width="75">T</tr>
<tr><td align="center" width="25">F<td align="center" width="25">T<td align="center" width="75">F<td align="center" width="25"><td align="center" width="25">F<td align="center" width="25">T<td align="center" width="75">T<td align="center" width="25"><td align="center" width="25">F<td align="center" width="25">T<td align="center" width="75">T</tr>
<tr><td align="center" width="25">F<td align="center" width="25">F<td align="center" width="75">F<td align="center" width="25"><td align="center" width="25">F<td align="center" width="25">F<td align="center" width="75">F<td align="center" width="25"><td align="center" width="25">F<td align="center" width="25">F<td align="center" width="75">T</tr>
<tr><td align="center" width="25"><td align="center" width="25"><td align="center" width="75"><td align="center" width="25"><td align="center" width="25"><td align="center" width="25"><td align="center" width="75"><td align="center" width="25"><td align="center" width="25"><td align="center" width="25"><td align="center" width="75"></tr>
<tr><td align="center" width="25"><u>A</u><td align="center" width="25"><u>B</u><td align="center" width="75"><u>A <b>nand </b>B</u><td align="center" width="25"><td align="center" width="25"><u>A</u><td align="center" width="25"><u>B</u><td align="center" width="75"><u>A <b>nor </b>B</u><td align="center" width="25"><td align="center" width="25"><u>A</u><td align="center" width="25"><u>B</u><td align="center" width="75"><u>A <b>xnor </b>B</u></tr>
<tr><td align="center" width="25"><td align="center" width="25"><td align="center" width="75"><td align="center" width="25"><td align="center" width="25"><td align="center" width="25"><td align="center" width="75"><td align="center" width="25"><td align="center" width="25"><td align="center" width="25"><td align="center" width="75"></tr>
<tr><td align="center" width="25">T<td align="center" width="25">F<td align="center" width="75">F<td align="center" width="25"><td align="center" width="25">T<td align="center" width="25">T<td align="center" width="75">F<td align="center" width="25"><td align="center" width="25">T<td align="center" width="25">T<td align="center" width="75">T</tr>
<tr><td align="center" width="25">T<td align="center" width="25">T<td align="center" width="75">T<td align="center" width="25"><td align="center" width="25">T<td align="center" width="25">F<td align="center" width="75">F<td align="center" width="25"><td align="center" width="25">T<td align="center" width="25">F<td align="center" width="75">F</tr>
<tr><td align="center" width="25">F<td align="center" width="25">T<td align="center" width="75">T<td align="center" width="25"><td align="center" width="25">F<td align="center" width="25">T<td align="center" width="75">F<td align="center" width="25"><td align="center" width="25">F<td align="center" width="25">T<td align="center" width="75">F</tr>
<tr><td align="center" width="25">F<td align="center" width="25">T<td align="center" width="75">T<td align="center" width="25"><td align="center" width="25">F<td align="center" width="25">F<td align="center" width="75">T<td align="center" width="25"><td align="center" width="25">F<td align="center" width="25">F<td align="center" width="75">T</tr>
<tr><td align="CENTER" width="75"><u>A</u><td align="CENTER" width="75"><b><u>not A</u></b></tr>
<tr><td align="CENTER" width="75"><td align="CENTER" width="75"></tr>
<tr><td align="CENTER" width="75">T<td align="CENTER" width="75">F</tr>
<tr><td align="CENTER" width="75">F<td align="CENTER" width="75">T</tr>
</table>
<p>For the short-circuit operations <b>and</b>, <b>or</b>, <b>nand</b>, and <b>nor</b> on types BIT and BOOLEAN, the right operand is evaluated only if the value of the left operand is not sufficient to determine the result of the operation. For operations <b>and</b> and <b>nand</b>, the right operand is evaluated only if the value of the left operand is T; for operations <b>or</b> and <b>nor</b>, the right operand is evaluated only if the value of the left operand is F.
<p>NOTE--All of the binary logical operators belong to the class of operators with the lowest precedence. The unary logical operator <b>not</b> belongs to the class of operators with the highest precedence.
<h3><a name="7.2.2"> <a href = "1076_7.HTM#7.2.2"> 7.2.2 </a> Relational operators</a></h3>
<p>Relational operators include tests for equality, inequality, and ordering of operands. The operands of each relational operator must be of the same type. The result type of each relational operator is the predefined type BOOLEAN.<br>
<br>
<center>
<table border="1">
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -