Question

In: Computer Science

Describe how each of Algol 60, Pascal, and Pytho 3 handles the dangling else problem.

Describe how each of Algol 60, Pascal, and Pytho 3 handles the dangling else problem.

Solutions

Expert Solution

Dangling else problem arise when this kind of statements occur in the program:

if b1 then
if b2 then
   S1
else
   S2

Above b1, b2 are conditions whereas S1 and S2 are statements.

What is the problem in the above statement?

Problem is that if b1 holds true but if b2 holds false then compiler got confused with
the subsequent else statement whether it is associated with first if that is having b1
condition or it is associated with second if that is b2 having condition.

Solution in Algol 60:

Algol 60 solve the problem of dangling else by restricting the use of if immediately after
then that is in our example after first if having b1 as condition another if is not allowed
in algol 60 having b2 as condition to solve this problem.

Solution in Pascal:

In pascal a different strategy is followed to solve the dangling else problem, here the ambiguous
else part is associated with innermost if that is in the example we considered else part is
associated with if having b2 condition.

Solution in python3:

In python 3 dangling else problem is solved by using indentation. Example

if b1:
   if b2:
       S1
   else:
       S2

Above else is assocaited with the if having b2 as condition because else is indented with this if.

But if the statement are written this way:

if b1:
   if b2:
       S1
else:
   S2

Here the else will be associated with the if having b1 as condition because it is indented with this
if.


Related Solutions

1)Write a C++ program which clearly demonstrates how the dangling else ambiguity is resolved. Your program...
1)Write a C++ program which clearly demonstrates how the dangling else ambiguity is resolved. Your program should print distinct results depending on if C++ uses inner-if or outer-if resolution. Turn in a listing of your program, the output, and a description of how your program demonstrates the semantic resolution of the ambiguity. 2) Give a context-free grammar describing the syntax of the following; Non-empty strings of 0’s and 1’s that represent binary numbers that have odd parity
Describe how OS’s manages resources and the way in which it handles processes.
Describe how OS’s manages resources and the way in which it handles processes.
this question is related to cloud computing. Describe how S3 handles consistency of objects and how...
this question is related to cloud computing. Describe how S3 handles consistency of objects and how this approach affects the state of objects when they are read using a GET.
For each of these 3 channels, describe where they are found, how they work, and the...
For each of these 3 channels, describe where they are found, how they work, and the role they play in physiology: 1) the cardiac ryanodine channel, 2) the voltage gated calcium channel on neurons, and 3) the dihydropyridine ryanodine channel
1) Describe, with 2-3 sentences for each, Type I and Type II Diabetes. How are they...
1) Describe, with 2-3 sentences for each, Type I and Type II Diabetes. How are they different from each other? 2) List at least 3-4 risk factors/causes for CVD 3) What are the top three types of cancer in men? Which are the top three types of cancer for women? 4) Which geographical regions of the world is tobacco use most prevalent? 5) List some of the health issues associated with alcohol abuse? List some of the social issues associated...
Describe the 3 major anatomical advances/adaptations that occurred in the vertebrates and explain how each added...
Describe the 3 major anatomical advances/adaptations that occurred in the vertebrates and explain how each added to its success and size increase
Describe Kohlberg’s theory of moral development. Write 1 paragraph for each of the 3 levels. How...
Describe Kohlberg’s theory of moral development. Write 1 paragraph for each of the 3 levels. How is this different from the Worldview Theory?
Show how to reduce 3-SAT problem to 3D-Matching problem.
Show how to reduce 3-SAT problem to 3D-Matching problem.
Problem 3 The following information is available for Hearst Company. Sales Price $60 Variable manufacturing costs...
Problem 3 The following information is available for Hearst Company. Sales Price $60 Variable manufacturing costs -34 Sales commission 10% of sales price -6 Fixed costs $180,000 Answer the following questions 1 What is the contribution margin? 2 What is the CM ratio? 3 What is the income if we sell 8,000 units? 4 What is the break-even point in units?, in dollars? 5 How many units must be sold to earn $40,000 6 The tax rate is 30%. How...
Problem 3-1 Lisa’s Dress Shop (LDS) experienced the following events in 2017.  Indicate how each of the...
Problem 3-1 Lisa’s Dress Shop (LDS) experienced the following events in 2017.  Indicate how each of the events affects the company’s financial statements, using the financial statement model provided.  LDS’ beginning balances for 2017 are Cash $100,000,  Common Stock $75,000 and Retained Earnings $25,000. 1. LDS purchased merchandise with a list price of $65,000 on account, terms 2/10, n/30. 2. The goods were purchased FOB shipping point with freight cost paid of $1,500 in cash. 3. (a) Sold merchandise for $80,000 to a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT