Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Simple question about if statemets

Reply
Thread Tools

Simple question about if statemets

 
 
gman
Guest
Posts: n/a
 
      12-11-2006
Hello All,
Assuming that all the following signal are std_logic, why isn't the
following line illegal:

if ( PCI_Frame_n = '0' or PCI_Trdy_n ='0' and Hit='1' and Term='0' or
Term = '1' and Ready ='1') then


The compiler says:
near "and": expecting: ')'
near "or": expecting: ')'

The problem seems to go away if I pair up the operands into groups of
two using parenthesis. Why doesn't the compiler apply
order-of-operation rules and evaluate the boolean statement?

Thanks.

 
Reply With Quote
 
 
 
 
Pascal Peyremorte
Guest
Posts: n/a
 
      12-11-2006
gman a écrit :
> Hello All,
> Assuming that all the following signal are std_logic, why isn't the
> following line illegal:
>
> if ( PCI_Frame_n = '0' or PCI_Trdy_n ='0' and Hit='1' and Term='0' or
> Term = '1' and Ready ='1') then
>
>
> The compiler says:
> near "and": expecting: ')'
> near "or": expecting: ')'
>
> The problem seems to go away if I pair up the operands into groups of
> two using parenthesis. Why doesn't the compiler apply
> order-of-operation rules and evaluate the boolean statement?


Not sure for VHDL (I'am a beginer) but on most languages, both "or" and "and"
have precedence on compare operators, so your expressions would be evaluated as:

if ( PCI_Frame_n = ('0' or PCI_Trdy_n) = ( .....

You must use :
> if ( (PCI_Frame_n = '0') or (PCI_Trdy_n ='0') and (Hit='1') and (Term='0') or


Be careful : the "and" operator have precedence on the "or". Writen like this,
your full line will be evaluated as :

if ( (PCI_Frame_n = '0') or
((PCI_Trdy_n ='0') and (Hit='1') and (Term='0')) or
((Term = '1') and (Ready ='1')) ) then

Is it exactely that you want ?
Be precise : time taken to type some parenthesis is never loosen !

Pascal
 
Reply With Quote
 
 
 
 
gman
Guest
Posts: n/a
 
      12-11-2006
I'm familiar with the order of operation rules. I'm trying to get the
boolean statement to evaluate as written i.e. the ANDs first (from left
to right) and then the ORs (from left to right). Regardless of the
order of operation, why does the compiler generate syntax errors?

Regards,

-Ali

Pascal Peyremorte wrote:
> gman a écrit :
> > Hello All,
> > Assuming that all the following signal are std_logic, why isn't the
> > following line illegal:
> >
> > if ( PCI_Frame_n = '0' or PCI_Trdy_n ='0' and Hit='1' and Term='0' or
> > Term = '1' and Ready ='1') then
> >
> >
> > The compiler says:
> > near "and": expecting: ')'
> > near "or": expecting: ')'
> >
> > The problem seems to go away if I pair up the operands into groups of
> > two using parenthesis. Why doesn't the compiler apply
> > order-of-operation rules and evaluate the boolean statement?

>
> Not sure for VHDL (I'am a beginer) but on most languages, both "or" and "and"
> have precedence on compare operators, so your expressions would be evaluated as:
>
> if ( PCI_Frame_n = ('0' or PCI_Trdy_n) = ( .....
>
> You must use :
> > if ( (PCI_Frame_n = '0') or (PCI_Trdy_n ='0') and (Hit='1') and (Term='0') or

>
> Be careful : the "and" operator have precedence on the "or". Writen like this,
> your full line will be evaluated as :
>
> if ( (PCI_Frame_n = '0') or
> ((PCI_Trdy_n ='0') and (Hit='1') and (Term='0')) or
> ((Term = '1') and (Ready ='1')) ) then
>
> Is it exactely that you want ?
> Be precise : time taken to type some parenthesis is never loosen !
>
> Pascal


 
Reply With Quote
 
Mark McDougall
Guest
Posts: n/a
 
      12-12-2006
gman wrote:

> I'm familiar with the order of operation rules. I'm trying to get the
> boolean statement to evaluate as written i.e. the ANDs first (from left
> to right) and then the ORs (from left to right). Regardless of the
> order of operation, why does the compiler generate syntax errors?


Coming from a C background, I've noticed that VHDL compilers sometimes
require what I consider 'superfluous' bracketing as well. I've never
bothered to look into it, I just add parentheses and keep going...

Regards,

--
Mark McDougall, Engineer
Virtual Logic Pty Ltd, <http://www.vl.com.au>
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
 
Reply With Quote
 
Ralf Hildebrandt
Guest
Posts: n/a
 
      12-12-2006
gman schrieb:


> if ( PCI_Frame_n = '0' or PCI_Trdy_n ='0' and Hit='1' and Term='0' or
> Term = '1' and Ready ='1') then



The compiler is as confused as me. Do you mean

if ( (PCI_Frame_n = '0' or PCI_Trdy_n ='0') and Hit='1' and Term='0' or
(Term = '1' and Ready ='1') ) then

or

if ( PCI_Frame_n = '0' or (PCI_Trdy_n ='0' and Hit='1' and Term='0') or
(Term = '1' and Ready ='1') ) then

or something else? There is no left-to-right elavuation in VHDL as in C.

Ralf
 
Reply With Quote
 
gman
Guest
Posts: n/a
 
      12-12-2006
What I'm trying to do is this in boolean:

!PCI_Frame_n + !PCI_Trdy_n*Hit* !Term+Term*Ready


Ralf Hildebrandt wrote:
> gman schrieb:
>
>
> > if ( PCI_Frame_n = '0' or PCI_Trdy_n ='0' and Hit='1' and Term='0' or
> > Term = '1' and Ready ='1') then

>
>
> The compiler is as confused as me. Do you mean
>
> if ( (PCI_Frame_n = '0' or PCI_Trdy_n ='0') and Hit='1' and Term='0' or
> (Term = '1' and Ready ='1') ) then
>
> or
>
> if ( PCI_Frame_n = '0' or (PCI_Trdy_n ='0' and Hit='1' and Term='0') or
> (Term = '1' and Ready ='1') ) then
>
> or something else? There is no left-to-right elavuation in VHDL as in C.
>
> Ralf


 
Reply With Quote
 
Ralf Hildebrandt
Guest
Posts: n/a
 
      12-12-2006
gman wrote:
> What I'm trying to do is this in boolean:
>
> !PCI_Frame_n + !PCI_Trdy_n*Hit* !Term+Term*Ready


Just set brackets to force the evaluation to the desired operator
precedence.

Ralf
 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      12-12-2006
VHDL does not allow parallel combinations of AND and OR in expressions.
You must use parentheses to specify the operation precedence you want.

Think about it; if we had a hard time trying to figure out what you
wanted, so would some poor sap that will have to maintain your design
in the future.

AND/OR precedence errors are a common error source in most programming,
so VHDL just forces you to explicitly tell it what you want.

Andy


gman wrote:
> What I'm trying to do is this in boolean:
>
> !PCI_Frame_n + !PCI_Trdy_n*Hit* !Term+Term*Ready
>
>
> Ralf Hildebrandt wrote:
> > gman schrieb:
> >
> >
> > > if ( PCI_Frame_n = '0' or PCI_Trdy_n ='0' and Hit='1' and Term='0' or
> > > Term = '1' and Ready ='1') then

> >
> >
> > The compiler is as confused as me. Do you mean
> >
> > if ( (PCI_Frame_n = '0' or PCI_Trdy_n ='0') and Hit='1' and Term='0' or
> > (Term = '1' and Ready ='1') ) then
> >
> > or
> >
> > if ( PCI_Frame_n = '0' or (PCI_Trdy_n ='0' and Hit='1' and Term='0') or
> > (Term = '1' and Ready ='1') ) then
> >
> > or something else? There is no left-to-right elavuation in VHDL as in C.
> >
> > Ralf


 
Reply With Quote
 
Ale Brewer
Guest
Posts: n/a
 
      01-10-2007
"gman" <(E-Mail Removed)> wrote in news:1165873311.697175.252830@
79g2000cws.googlegroups.com:

> Hello All,
> Assuming that all the following signal are std_logic, why isn't the
> following line illegal:
>
> if ( PCI_Frame_n = '0' or PCI_Trdy_n ='0' and Hit='1' and Term='0' or
> Term = '1' and Ready ='1') then
>
>
> The compiler says:
> near "and": expecting: ')'
> near "or": expecting: ')'
>
> The problem seems to go away if I pair up the operands into groups of
> two using parenthesis. Why doesn't the compiler apply
> order-of-operation rules and evaluate the boolean statement?
>
> Thanks.
>


It is because AND and OR are boolean operators.


if (( PCI_Frame_n = '0') or (PCI_Trdy_n ='0') and (Hit='1') and (Term='0')
or (Term = '1') and (Ready ='1')) then

should compile

--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      01-10-2007
Nope, AND and OR are defined for std_logic too. However, the result is
still a std_logic, and thus the entire expression must be compared to
'1' or '0' to return a boolean which is required in the IF condition.

if (not pci_frame_n or (not pci_trdy_n and hit and not term) or (term
and ready)) = '1' then

No final, all-enclosing parentheses are required either.

Andy

Ale Brewer wrote:
>
> It is because AND and OR are boolean operators.
>
>
> if (( PCI_Frame_n = '0') or (PCI_Trdy_n ='0') and (Hit='1') and (Term='0')
> or (Term = '1') and (Ready ='1')) then
>
> should compile
>
> --
> Posted via a free Usenet account from http://www.teranews.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Plz, a simple answer to a simple question about IP addresses MeekiMoo Computer Support 0 07-28-2009 08:10 AM
Simple region code question... simple answer?? joseph.greer@gmail.com DVD Video 7 01-26-2007 09:07 PM
Simple Question - Simple Answer? Daniel Frey XML 4 01-12-2005 04:25 PM
Re: Simple Simple question!!! Kevin Spencer ASP .Net 0 06-25-2004 05:25 PM
Re: Simple Simple question!!! ashelley@inlandkwpp.com ASP .Net 0 06-25-2004 04:18 PM



Advertisments