Abstract
The dangling else problem consists of a class of potential ambiguities in ALGOL-like conditional statements whose basic form is “if B1 then if B2 then S1 else S2” where B1 and B2 are Boolean expressions and S1 and S2 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 S1 be statements. We define S to be closed if “S else S1” is not a statement, and to be open if “S else S1” 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.
- 1 ARDEN, B., GALLER, B., AND GRAHAM, R. The MAD Manual. U. of Michigan Press, Ann Arbor, Mich., 1965.Google Scholar
- 2 BURKHARDT, W. Syntax and generalization of ALGOL 60. (Letter to the editor) Comm. ACM 8 (May 1965), 261. Google ScholarDigital Library
- 3 COBOL-1961: revised specifications for a common business oriented language. Publ. 0-598941, U.S. Government Printing Office, Washington, D.C., 1961.Google Scholar
- 4 FLOYD, R. Syntactic analysis and operator precedence. J ACM 10, 3 (July 1963), 316-333. Google ScholarDigital Library
- 5 PL/I: Language specifications. Form C26-6571-2, IBM Programming Systems Publications, Poughkeepsie, N.Y., Jan. 1966.Google Scholar
- 6 KAUPE, A. A note on the dangling else in ALGOL 60. Comm. ACM 6 (Aug. 1963), 460-462. Google ScholarDigital Library
- 7 NAUR, P., AND WOODGER, M. (Eds.) Revised report on the algorithmic language ALGOL 60. Comm. ACM 6 (Jan. 1963), 1-17. Google ScholarDigital Library
- 8 NAUR, P. (Ed.) Report on the algorithmic language ALGOL 60. Comm. ACM 8 (May 1960), 299-314. Google ScholarDigital Library
- 9 WIRTH, N., AND WEBER, H. EULER: A generalization of ALGOL, and its formal definition: Pt. II. Comm. ACM 9 (Feb. 1966), 89-99. Google ScholarDigital Library
- 10 SHAW, C. A specification of JOVIAL. Comm. ACM 6, 12 (Dec. 1963), 721-736. Google ScholarDigital Library
Index Terms
- A final solution to the Dangling else of ALGOL 60 and related languages
Recommendations
A note on the dangling else ALGOL 60
Some revisions of ALGOL 60 are proposed, which not only eliminate certain ambiguous statements but also add some convenience to the language. A discussion of the background of the problem and a sketch of a proof that the ambiguities have been removed is ...
ALGOL 60 confidential
The ALGOL 60 Report,* when first encountered, seems to describe a very complex language which will be difficult to learn. The “metalinguistic formulae” admirably serve the purpose of precisely specifying a language, but they are certainly not very ...
A syntax directed compiler for ALGOL 60
Special 25th Anniversary IssueAlthough one generally thinks of a compiler as a program for a computer which translates some object language into a target language, in fact this program also serves to define the object language in terms of the target language. In early compilers, ...
Comments