[comp.lang.c] isomorphic languages

dgh%dgh@Sun.COM (David Hough) (10/30/88)

Thesis:  Language designers (including X3Jn committees) needn't
incorporate every bad syntax of the past if revised versions are
syntactically isomorphic.

One thing I've noticed in the current Fortran-8x discussion and in some
previous X3J11 C discussions is that new users of the new languages are
predestined to a lot of agony on the cross of literal compatibility.
These new users are destined to repeat all the mistakes necessary to
learn the tricks of the masters.  Of course, the masters don't regard
these mistakes as flaws in the languages, but as features, which
furthermore help maintain full employment for the masters.

I'd consider Fortran-8x to be upwardly compatible with Fortran-77, and
X3J11 C to be upwardly compatible from K&R, if every legal old program
could be converted to a legal new program by a "context-free"
translator that only has to look at one logical input line at a time.
One logical input line may contain multiple physical input lines -
Fortran-77 continuation lines are what I have in mind.  Languages with
this "context-free translatability" property could be called
"syntactically isomorphic".

In the last public review I urged X3J3 to be bold about devising modern
syntax for Fortran-8x.  I don't think it's necessary for Fortran-8x
compilers to accept Fortran-77 >syntax< if it is possible to provide a
translator as described above.  "Possible" means possible according to
the syntactical differences rather than according to the possible
skills of translator implementors; the requirement that a context-free
translation be possible is intended to minimize the skill requirement.
Furthermore, thanks to people like Richard Stallman, such translators
would be readily available in the public domain.

Note that unfortunately Fortran-8x will have to accept Fortran-77
>semantics<, which is most of the hard part, however expressed, so the
complexity of the total compiler wouldn't be much lessened; the thrust
of this proposal is to eliminate the known syntactic stumbling blocks.

Thus there's no reason to continue to inflict bugs like

	do i = 1. 10

or its C counterpart

	if(x=y) ...

It's too late for X3J11 this time around, but I can at least hope for a
better result from X3J3.

David Hough

dhough@sun.com   
na.hough@na-net.stanford.edu
{ucbvax,decvax,decwrl,seismo}!sun!dhough

khb%chiba@Sun.COM (Keith Bierman - Sun Tactical Engineering) (10/30/88)

In article <75326@sun.uucp> dgh%dgh@Sun.COM (David Hough) writes:
>Thesis:  Language designers (including X3Jn committees) needn't
>incorporate every bad syntax of the past if revised versions are
>syntactically isomorphic.
>
>  < stuff deleted >
>I'd consider Fortran-8x to be upwardly compatible with Fortran-77, and
>X3J11 C to be upwardly compatible from K&R, if every legal old program
>could be converted to a legal new program by a "context-free"
>translator that only has to look at one logical input line at a time.
>One logical input line may contain multiple physical input lines -
>Fortran-77 continuation lines are what I have in mind.  Languages with
>this "context-free translatability" property could be called
>"syntactically isomorphic".
>
< more stuff deleted >

I agree, but with one modest addition. The translator must be
bidirectional. If a program does not use any of the languages new
features (that don't correspond to anything in the old language), it
should be convertable back into an old format. 

This is necessary for supporting multi-platform projects, where one
cannot be sure that all vendors will supply a new compiler in a timely
fashion. 

Also if the original program was readable (well indented, and
commented, etc.) the converted (or doubly converted) should still be.

With these two proviso's added, I agree with David's proposal.

Keith H. Bierman
It's Not My Fault ---- I Voted for Bill & Opus

ok@quintus.uucp (Richard A. O'Keefe) (10/31/88)

In article <75328@sun.uucp> khb@sun.UUCP (Keith Bierman - Sun Tactical Engineering) writes:
>In article <75326@sun.uucp> dgh%dgh@Sun.COM (David Hough) writes:
>>Thesis:  Language designers (including X3Jn committees) needn't
>>incorporate every bad syntax of the past if revised versions are
>>syntactically isomorphic.

>Also if the original program was readable (well indented, and
>commented, etc.) the converted (or doubly converted) should still be.

In _one_ respect, such a conversion is easier for Fortran, because
Fortran 77 only permits comments _between_ statements.  Bierman asks
for the translation to be invertible if the F8x version doesn't use
anything not in F77, a backwards translator wouldn't have to get
within-statement comments exactly right.

This problem is familiar to people who've tried to translate between
Lisp (or Prolog) dialects.  For a C illustration of the problem, suppose
that the replacement for
	for (<init>; <test>; <step>) <stmt>
were
	for <init> doing <step> while <test> do <stmt> repeat
and consider input like
	for (p = &(this->link[i]);	/* Note that in this loop over */
	     *p != NULL;		/* the ith bucket, p is a POINTER */
	     p => &(p->next)		/* to a pointer to an entry, NOT */
	    ) {				/* a pointer to an entry. */
	    ....
	}
The reordering of the constituents in the revised language is going to
do terrible things to the text of the comment...

This is not a problem with programs which conform to the F77 standard,
as it provides no way of writing such comments.  But some _processors_
which conform to the F77 standard provide in-line comments as an
extension.  (Perhaps the majority of such processors?)  Don't expect
it to be easy to preserve good indentation and commenting.
[If anyone knows how to do it, please tell me at once!]

johnl@ima.ima.isc.com (John R. Levine) (11/02/88)

In article <604@quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes:
>In _one_ respect, such a conversion is easier for Fortran, because
>Fortran 77 only permits comments _between_ statements.  Bierman asks
>for the translation to be invertible if the F8x version doesn't use
>anything not in F77, a backwards translator wouldn't have to get
>within-statement comments exactly right.

Actually, section 3.2.1 of the F77 standard says that "Comment lines may
appear between the initial line and its first continuation line or between
two continuation lines."  It also says that a line which is blank in the
first 72 columns is a comment line, which is a minor pain for us compiler
writers.

Nonetheless, the whole issue of preserving comment blocks when translating
languages is a murky one, and one that I've never seen addressed very well.
But if that's the worst problem encoutered in an F77<->F8x translator, we're
in a lot better shape than I expect.
-- 
John R. Levine, IECC, PO Box 349, Cambridge MA 02238-0349, +1 617 492 3869
{ bbn | think | decvax | harvard | yale }!ima!johnl, Levine@YALE.something
Rome fell, Babylon fell, Scarsdale will have its turn.  -G. B. Shaw