skip to main content
article
Free Access

A final solution to the Dangling else of ALGOL 60 and related languages

Published:01 September 1966Publication History
Skip Abstract Section

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.

References

  1. 1 ARDEN, B., GALLER, B., AND GRAHAM, R. The MAD Manual. U. of Michigan Press, Ann Arbor, Mich., 1965.Google ScholarGoogle Scholar
  2. 2 BURKHARDT, W. Syntax and generalization of ALGOL 60. (Letter to the editor) Comm. ACM 8 (May 1965), 261. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. 3 COBOL-1961: revised specifications for a common business oriented language. Publ. 0-598941, U.S. Government Printing Office, Washington, D.C., 1961.Google ScholarGoogle Scholar
  4. 4 FLOYD, R. Syntactic analysis and operator precedence. J ACM 10, 3 (July 1963), 316-333. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 5 PL/I: Language specifications. Form C26-6571-2, IBM Programming Systems Publications, Poughkeepsie, N.Y., Jan. 1966.Google ScholarGoogle Scholar
  6. 6 KAUPE, A. A note on the dangling else in ALGOL 60. Comm. ACM 6 (Aug. 1963), 460-462. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. 7 NAUR, P., AND WOODGER, M. (Eds.) Revised report on the algorithmic language ALGOL 60. Comm. ACM 6 (Jan. 1963), 1-17. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. 8 NAUR, P. (Ed.) Report on the algorithmic language ALGOL 60. Comm. ACM 8 (May 1960), 299-314. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 10 SHAW, C. A specification of JOVIAL. Comm. ACM 6, 12 (Dec. 1963), 721-736. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A final solution to the Dangling else of ALGOL 60 and related languages
    Index terms have been assigned to the content through auto-classification.

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image Communications of the ACM
      Communications of the ACM  Volume 9, Issue 9
      Sept. 1966
      55 pages
      ISSN:0001-0782
      EISSN:1557-7317
      DOI:10.1145/365813
      Issue’s Table of Contents

      Copyright © 1966 ACM

      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 1 September 1966

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader