Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!rochester!cornell!uw-beaver!fluke!kurt From: kurt@fluke.UUCP Newsgroups: net.lang Subject: Re: compound statements Message-ID: <361@dragon.fluke.UUCP> Date: Fri, 11-Jul-86 12:15:17 EDT Article-I.D.: dragon.361 Posted: Fri Jul 11 12:15:17 1986 Date-Received: Tue, 15-Jul-86 06:48:18 EDT References: <5281@topaz.RUTGERS.EDU> <2296@umcp-cs.UUCP> Organization: John Fluke Mfg. Co., Inc., Everett, WA Lines: 39 Q: Why do many languages require the statement that is the body of a function to be a compound statement? A1: Languages which permit the null statement are ambiguous in a serious and not intuitively resolvable way. (This was pointed out previously). A2: Using a statement block delimits the function. This is important visually and syntactically. Just because it is *possible* to parse a single statement as the statement block does not make it a good idea. Consider the problem of parser error recovery. Good error recovery is more probable when there is a good chance of finding the block/function delimiting END statement. If this statement is not available, error recovery actions may eat into the following declaration, with confusing and comical results. As mentioned in another article, the visual delimitation is helpful in reading the code. The original claim was that it was easier to read if the function body was a single statement. This is possibly true, but we can't write parsers that say, "If the function body is only a couple of lines, it may be a single statement. Otherwise it must be a block." A3: Some recent languages use a "comb" syntactic structure to evade this problme altogether. Consider this obviously psudo-code integer function factorial (x) is integer x if x = 1 then return 1 else return x * factorial (x) end if end factorial The function is delimited on top and bottom. So is the if statement. Ada has this approximate structure. A 1-line body is possible, and the statement doesn't have to be enclosed in a block. In fact, blocks are completely unnecessary in such languages, although they are often provided to delimit scope for local variable definition.