Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!decwrl!labrea!sri-unix!garth!smryan From: smryan@garth.UUCP (Steven Ryan) Newsgroups: comp.lang.c Subject: Re: Need C language Description Summary: On formally defined languages. Message-ID: <1131@garth.UUCP> Date: 1 Aug 88 20:06:26 GMT References: <12707@agate.BERKELEY.EDU> <1104@garth.UUCP> <8270@brl-smoke.ARPA> <1112@garth.UUCP> <6492@bloom-beacon.MIT.EDU> Reply-To: smryan@garth.UUCP (Steven Ryan) Organization: INTERGRAPH (APD) -- Palo Alto, CA Lines: 89 >I have sitting in front of me the 1.31.87 version of "High C Language >Reference Manual". [I wonder if that's a reference to Hi C?] >I'll quote from it, without permission, to see if you think their >formal definition is sufficiently formal: > >\begin{quote} >7.7 for > >Syntax > >Statement -> 'for' '(' First: EL? ';' > Next: EL? ';' > Last: EL? > ')' Body: Statement > >Constraints: > `Next', if present, must have a scalar type. In the style of A68 RR: NEST for statment: for token,NEST for control pack,NEST controlled statement. NEST for control: NEST initial expression,semicolon token, NEST next expression,semicolon token, NEST last expression. NEST initial expression: TYPE NEST expression list. NEST next expression: {This is what I mean by formal context} TYPE NEST expression list, {sensitive grammar. The tools are } where TYPE is scalar type; {available though unused. } EMPTY. NEST final expression: TYPE NEST expression list. NEST controlled statement: loop level NEST statement. {Mark loop for contained break/continue.} >Semantics: > If `Next' is omitted, `1' is implied. > > Except in the matter of a contained _continue_ `Statement' in >the `Body', this statement is exactly equivalent to > > First; while (Next) { Body; Last; } > >Thys, the `First' and `Next' evaluation ends are sequence points. In the for statement S, let F be the first expression, N be the next expression if not null otherwise 1, let be L be the last expression, let C be the controlled statement. The evaluation of S is (a) the evaluation of F (b) the evaluation of N If the yield of N is a true value, (i) the evaluation of C {Need to include something here so that the evaluation of break or continue within C terminates the evaluation of C here and possibly the evaluation of S. It's difficult to do in isolation of the entire grammar, but at least the declaration nest is marked.} (ii) the evaluation of L (iii) the evaluation of the for statement S' with F' empty, N' is N, L' is L, C' is C. If the yield of N is a false value, (iv) the evaluation of S is complete. >Discussion: > The first expression is a convenient place to put any >initialization for the loop. The second specifies a test for >continuing the loop and perhaps an incrementation. The third usually >specifies an operation performed at the end of the loop, such as an >increment of a variable. {How to use the language is not part of the definition--it belongs in tutorials. However to explain some of the subtleties, comments can be included so long as they are not considerred part of the definition.} >\end{quote} > >I wish MetaWare had spent less time making Ada-like extensions to C >(their compiler supports Ada-style "keyword" arguments with defaults, >for example, which you are not going to find in any other compiler), It's nice to see somebody make a stab at a complete definition. Now if if everybody can agree to this definition (assuming it is complete and all ambiguities are resolved) C will finally be formally defined. The fact that contains extensions (what C compiler doesn't?) makes that unlikely.