Simple question about if statemets

G

gman

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.
 
P

Pascal Peyremorte

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
 
G

gman

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
 
M

Mark McDougall

gman said:
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,
 
R

Ralf Hildebrandt

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
 
G

gman

What I'm trying to do is this in boolean:

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

Ralf Hildebrandt

gman said:
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
 
A

Andy

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
 
A

Ale Brewer

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
 
A

Andy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top