A final solution to the Dangling else of ALGOL 60 and related languages
- 1 September 1966
- journal article
- Published by Association for Computing Machinery (ACM) in Communications of the ACM
- Vol. 9 (9) , 679-682
- https://doi.org/10.1145/365813.365821
Abstract
The dangling else problem consists of a class of potential ambiguities in ALGOL-like conditional statements whose basic form is “if B 1 then if B 2 then S 1 else S 2” where B 1 and B 2 are Boolean expressions and S 1 and S 2 are basic statements. The difficulty lies in whether to attach the else to the first if or to the second one. Existing solutions to the problem are either ambiguous or unnecessarily restrictive. Let S and S 1 be statements. We define S to be closed if “ S else S 1” is not a statement, and to be open if “ S else S 1” is a statement. Thus an unconditional statement is a closed statement. Open and closed conditional statements are defined by syntax equations in such a way as to preserve openness and closure. In each case, an else must always be preceded by a closed statement. It is shown that the syntax equations are unambiguous, and that any change in the statement types required within the syntax equations would lead to either ambiguity or unnecessary restriction.Keywords
This publication has 7 references indexed in Scilit:
- EULERCommunications of the ACM, 1966
- Letters to the editor: syntax and generalization of ALGOL 60Communications of the ACM, 1965
- A specification of JOVIALCommunications of the ACM, 1963
- A note on the dangling else ALGOL 60Communications of the ACM, 1963
- Syntactic Analysis and Operator PrecedenceJournal of the ACM, 1963
- Revised report on the algorithmic language ALGOL 60Communications of the ACM, 1963
- Report on the algorithmic language ALGOL 60Communications of the ACM, 1960