app1.1.htm
来自「介绍asci设计的一本书」· HTM 代码 · 共 423 行
HTM
423 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML EXPERIMENTAL 970324//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="Adobe FrameMaker 5.5/HTML Export Filter">
<TITLE> A.1 BNF</TITLE></HEAD><!--#include file="top.html"--><!--#include file="header.html"-->
<DIV>
<P>[ <A HREF="APP1.htm">Chapter start</A> ] [ <A HREF="APP1.htm">Previous page</A> ] [ <A HREF="APP1.2.htm">Next page</A> ]</P><!--#include file="AmazonAsic.html"--><HR></DIV>
<H1 CLASS="zAppHeading1">
<A NAME="pgfId=157">
</A>
A.1 <A NAME="11550">
</A>
BNF</H1>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=41420">
</A>
Appendix A of the LRM describes the syntax of VHDL using <A NAME="marker=73315">
</A>
<SPAN CLASS="Definition">
keywords</SPAN>
(or <A NAME="marker=73316">
</A>
<SPAN CLASS="Definition">
reserved words</SPAN>
) and characters in a shorthand notation called the <A NAME="marker=159">
</A>
<SPAN CLASS="Definition">
BNF</SPAN>
(<A NAME="marker=162">
</A>
<SPAN CLASS="Definition">
Backus–Naur form</SPAN>
). As an example, the BNF definition given in Appendix A of the LRM for the syntax of the <SPAN CLASS="BodyComputer">
wait</SPAN>
statement is</P>
<P CLASS="zAppComputerFirst">
<A NAME="pgfId=171">
</A>
wait_statement ::=</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=173">
</A>
[label : ] <SPAN CLASS="ComputerKeyword">
wait</SPAN>
[ sensitivity_clause ] [ condition_clause ]</P>
<P CLASS="zAppComputerLast">
<A NAME="pgfId=1991">
</A>
[ timeout_clause ] ;</P>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=179">
</A>
This definition means: “The <SPAN CLASS="BodyComputer">
wait</SPAN>
statement consists of the keyword, <SPAN CLASS="BodyComputer">
wait</SPAN>
, followed by three optional parts: a sensitivity clause, a condition clause, and a timeout clause.”</P>
<P CLASS="zAppBody">
<A NAME="pgfId=199">
</A>
You treat the BNF as a series of equations. The left-hand side is called a <A NAME="marker=187">
</A>
<SPAN CLASS="Definition">
production</SPAN>
or <A NAME="marker=190">
</A>
<SPAN CLASS="Definition">
construct</SPAN>
, the symbol <SPAN CLASS="BodyComputer">
::=</SPAN>
<A NAME="marker=44481">
</A>
(two colons and an equal sign) represents <A NAME="marker=192">
</A>
<SPAN CLASS="Definition">
equivalence</SPAN>
, the right-hand side contains the <A NAME="marker=194">
</A>
<SPAN CLASS="Definition">
parts</SPAN>
that comprise the production. Parts may be keywords (in bold here). Parts may be other productions contained in <A NAME="marker=44475">
</A>
square <A NAME="marker=44480">
</A>
brackets <SPAN CLASS="BodyComputer">
[]</SPAN>
<A NAME="marker=44476">
</A>
. This signifies that the part is optional. Parts may also have <A NAME="marker=44479">
</A>
curly brackets or <A NAME="marker=44478">
</A>
braces <SPAN CLASS="BodyComputer">
{}</SPAN>
<A NAME="marker=44477">
</A>
. This indicates that the part is optional and may be repeated. The BNF is hierarchical; for example, the <SPAN CLASS="BodyComputer">
wait</SPAN>
statement is defined in terms of other constructs. We can expand the <SPAN CLASS="BodyComputer">
wait</SPAN>
statement definition, by substituting the BNF for <SPAN CLASS="BodyComputer">
sensitivity_clause</SPAN>
, <SPAN CLASS="BodyComputer">
condition_clause</SPAN>
, and <SPAN CLASS="BodyComputer">
timeout_clause</SPAN>
:</P>
<P CLASS="zAppComputerFirst">
<A NAME="pgfId=10248">
</A>
wait_statement ::=</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=10249">
</A>
[label : ] <SPAN CLASS="ComputerKeyword">
wait</SPAN>
</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=10250">
</A>
[ <SPAN CLASS="ComputerKeyword">
on</SPAN>
<SPAN CLASS="ComputerEmphasis">
signal</SPAN>
_name { , <SPAN CLASS="ComputerEmphasis">
signal</SPAN>
_name } ]</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=10251">
</A>
[ <SPAN CLASS="ComputerKeyword">
until</SPAN>
<SPAN CLASS="ComputerEmphasis">
boolean</SPAN>
_expression ]</P>
<P CLASS="zAppComputerLast">
<A NAME="pgfId=10252">
</A>
[ <SPAN CLASS="ComputerKeyword">
for</SPAN>
<SPAN CLASS="ComputerEmphasis">
time</SPAN>
_expression ] ;</P>
<P CLASS="zAppBody">
<A NAME="pgfId=10253">
</A>
Expanding the BNF makes it easier to see the structure of the <SPAN CLASS="BodyComputer">
wait</SPAN>
statement. The expanded BNF shows that the following are valid <SPAN CLASS="BodyComputer">
wait</SPAN>
statements (as far as syntax is concerned):</P>
<P CLASS="zAppComputerFirst">
<A NAME="pgfId=10254">
</A>
<SPAN CLASS="ComputerKeyword">
wait</SPAN>
;</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=10255">
</A>
<SPAN CLASS="ComputerKeyword">
wait</SPAN>
<SPAN CLASS="ComputerKeyword">
on</SPAN>
a;</P>
<P CLASS="zAppComputerLast">
<A NAME="pgfId=10256">
</A>
<SPAN CLASS="ComputerKeyword">
wait</SPAN>
<SPAN CLASS="ComputerKeyword">
on</SPAN>
a, b, c <SPAN CLASS="ComputerKeyword">
until</SPAN>
count = 0 <SPAN CLASS="ComputerKeyword">
for</SPAN>
1 + 1 ns;</P>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=77117">
</A>
A disadvantage of expanding the BNF is that we lose the names and the definitions of the intermediate constructs (<SPAN CLASS="BodyComputer">
sensitivity_clause</SPAN>
, <SPAN CLASS="BodyComputer">
condition_clause</SPAN>
, and <SPAN CLASS="BodyComputer">
timeout_clause</SPAN>
). The VHDL-93 LRM uses 238 production rules; the following section contains the same definitions in BNF, but in expanded form (using 94 rules).</P>
<P CLASS="zAppBody">
<A NAME="pgfId=77118">
</A>
There is one other disadvantage of expanding the BNF syntax definitions. Expanding the definition of a loop statement illustrates this problem:</P>
<P CLASS="zAppComputerFirst">
<A NAME="pgfId=4416">
</A>
loop_statement ::=</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=4421">
</A>
[ <SPAN CLASS="ComputerEmphasis">
loop</SPAN>
_label : ]</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=4418">
</A>
[ iteration_scheme ] <SPAN CLASS="ComputerKeyword">
loop</SPAN>
</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2058">
</A>
sequence_of_statements</P>
<P CLASS="zAppComputerLast">
<A NAME="pgfId=2059">
</A>
end loop [ <SPAN CLASS="ComputerEmphasis">
loop</SPAN>
_label ] ;</P>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=2047">
</A>
The definition of <SPAN CLASS="BodyComputer">
sequence_of_statements</SPAN>
is</P>
<P CLASS="zAppComputerOneLine">
<A NAME="pgfId=2062">
</A>
sequence_of_statements ::= {sequential_statement}</P>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=80414">
</A>
The definition of <SPAN CLASS="BodyComputer">
iteration_scheme</SPAN>
is</P>
<P CLASS="zAppComputerOneLine">
<A NAME="pgfId=2067">
</A>
iteration_scheme ::= <SPAN CLASS="ComputerKeyword">
while</SPAN>
condition | <SPAN CLASS="ComputerKeyword">
for</SPAN>
<SPAN CLASS="ComputerEmphasis">
loop</SPAN>
_parameter_specification</P>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=2076">
</A>
The definitions of <SPAN CLASS="BodyComputer">
condition</SPAN>
and <SPAN CLASS="BodyComputer">
parameter_specification</SPAN>
are</P>
<P CLASS="zAppComputerFirst">
<A NAME="pgfId=2072">
</A>
condition ::= <SPAN CLASS="ComputerEmphasis">
boolean</SPAN>
_expression</P>
<P CLASS="zAppComputerLast">
<A NAME="pgfId=2096">
</A>
parameter_specification ::= identifier in discrete_range</P>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=2103">
</A>
The definition of <SPAN CLASS="BodyComputer">
discrete_range</SPAN>
is</P>
<P CLASS="zAppComputerOneLine">
<A NAME="pgfId=2097">
</A>
discrete_range ::= <SPAN CLASS="ComputerEmphasis">
discrete</SPAN>
_subtype_indication | range</P>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=2113">
</A>
If we stop expanding at this level, we can write out what we have so far in our expanded definition of a loop statement:</P>
<P CLASS="zAppComputerFirst">
<A NAME="pgfId=2010">
</A>
loop_statement ::=</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2011">
</A>
[ <SPAN CLASS="ComputerEmphasis">
loop</SPAN>
_label : ] </P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2012">
</A>
[ <SPAN CLASS="ComputerKeyword">
while</SPAN>
<SPAN CLASS="ComputerEmphasis">
boolean</SPAN>
_expression</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2137">
</A>
| <SPAN CLASS="ComputerKeyword">
for</SPAN>
identifier <SPAN CLASS="ComputerKeyword">
in</SPAN>
discrete_range ]</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2013">
</A>
<SPAN CLASS="ComputerKeyword">
loop</SPAN>
</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2014">
</A>
{sequential_statement}</P>
<P CLASS="zAppComputerLast">
<A NAME="pgfId=2015">
</A>
end loop [ <SPAN CLASS="ComputerEmphasis">
loop</SPAN>
_label ] ;</P>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=2038">
</A>
There is (theoretically) some ambiguity in this definition as far as the choices either side of the <SPAN CLASS="BodyComputer">
|</SPAN>
symbol are concerned. Does this definition mean that we choose between <SPAN CLASS="BodyComputerKeyword">
while</SPAN>
<SPAN CLASS="BodyComputer">
</SPAN>
<SPAN CLASS="BodyComputerEmphasis">
boolean</SPAN>
<SPAN CLASS="BodyComputer">
_expression</SPAN>
and <SPAN CLASS="BodyComputerKeyword">
for</SPAN>
<SPAN CLASS="BodyComputer">
identifier </SPAN>
<SPAN CLASS="BodyComputerKeyword">
in</SPAN>
<SPAN CLASS="BodyComputer">
discrete_range</SPAN>
? If we were in a contrary mood, we could also interpret the BNF as indicating a choice between <SPAN CLASS="BodyComputerEmphasis">
boolean</SPAN>
<SPAN CLASS="BodyComputer">
_expression</SPAN>
and <SPAN CLASS="BodyComputerKeyword">
for</SPAN>
. Notice that this ambiguity is also present in the definition of <SPAN CLASS="BodyComputer">
iteration_scheme</SPAN>
. </P>
<P CLASS="zAppBody">
<A NAME="pgfId=79154">
</A>
Adding angle brackets around the clauses, <SPAN CLASS="BodyComputer">
< </SPAN>
<SPAN CLASS="ComputerKeyword">
while</SPAN>
<SPAN CLASS="BodyComputer">
... > | < </SPAN>
<SPAN CLASS="ComputerKeyword">
for</SPAN>
<SPAN CLASS="BodyComputer">
... ></SPAN>
, makes the grouping of choices clear:</P>
<P CLASS="zAppComputerFirst">
<A NAME="pgfId=2028">
</A>
loop_statement ::=</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2029">
</A>
[ <SPAN CLASS="ComputerEmphasis">
loop</SPAN>
_label : ] </P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2030">
</A>
[ < <SPAN CLASS="ComputerKeyword">
while</SPAN>
<SPAN CLASS="ComputerEmphasis">
boolean</SPAN>
_expression ></P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2036">
</A>
| < <SPAN CLASS="ComputerKeyword">
for</SPAN>
identifier <SPAN CLASS="ComputerKeyword">
in</SPAN>
discrete_range > ]</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2031">
</A>
loop</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=2032">
</A>
{ sequential_statement }</P>
<P CLASS="zAppComputerLast">
<A NAME="pgfId=2033">
</A>
end loop [ <SPAN CLASS="ComputerEmphasis">
loop</SPAN>
_label ] ;</P>
<P CLASS="zAppBodyAfterHead">
<A NAME="pgfId=2042">
</A>
Unfortunately the symbols <SPAN CLASS="BodyComputer">
<</SPAN>
and <SPAN CLASS="BodyComputer">
></SPAN>
are already valid lexical elements in VHDL. In fact, since <SPAN CLASS="BodyComputer">
{}</SPAN>
and <SPAN CLASS="BodyComputer">
[]</SPAN>
are already used, and <SPAN CLASS="BodyComputer">
()</SPAN>
are part of the language too, there are no brackets left to use. We live with this inconvenience. The BNF (here or in the LRM) does not define VHDL, but helps us understand it.</P>
<HR><P>[ <A HREF="APP1.htm">Chapter start</A> ] [ <A HREF="APP1.htm">Previous page</A> ] [ <A HREF="APP1.2.htm">Next page</A> ]</P></BODY>
<!--#include file="Copyright.html"--><!--#include file="footer.html"-->
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?