Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

evaluation of expression

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How to evaluate the following expression


Can any one of u tell me, which operators are left associative and which operators are right associative?

Thanx in advance
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
After the execution of this expression b1 will have value
FALSE as this expression consists of subexpressions, and therefore
first of all subexpressions will be evaluated
in given question
boolean b1 = false?false:true?false:true?false:true;
it will break to
boolean b1 = (false?false true?false true?false:true)));
and result is accordingly...........
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It ultimately boils down from the rightmost to the left. The subexpressions get executed and the results assigned and this continues in a chain from right to left.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is one of those
"think-like-a-compiler" kinda question.

lets see how we can evaluate this expression.
move from left to right as per associativity rules.

step 1: input--> false?false:true?false:true?false:true;
output--> false?false true?false:true?false:true);

step 2: input--> false?false true?false:true?false:true);
output--> false?false true?false true?false:true));

step 3: input--> false?false true?false true?false:true));
output--> false?false true?false true?false true)));

brackets shud clear your doubt a little bit....
does it??

-Narender
"Rock Steady"
 
Narender Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh nooooooooo....
i didnt not put soooo many sad emoticons in my message.

 
Narender Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am not gonna give up this easy.


step 1: input--> false?false:true?false:true?false:true;
output--> false?false: (true?false:true?false:true);

step 2: input--> false?false: (true?false:true?false:true);
output--> false?false: (true?false: (true?false:true));

step 3: input--> false?false: (true?false: (true?false:true));
output--> false?false: (true?false: (true?false true)));
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic