Re: Aspects of programming languages in common

From: James Harris (no.email.please)
Date: 04/26/04


Date: Mon, 26 Apr 2004 22:36:45 +0100


"James Rogers" <jimmaureenrogers@att.net> wrote in message
<snip>
> >> The basic question is, What prevents these mainstream languages
> >> being translated to an intermediate form as proposed?
> >>
> > It happens already. A lot of language suites consist of front ends for C,
> > C++, FORTRAN etc, and then a common optimiser and library system for the
> > back end.
> >
>
> I don't think that is exactly what the OP is talking about.
> A lot of languages are translated into C and then compiled through
> a C compiler. They undergo a syntax evaluation before being
> translated into C.
>
> My understanding of the proposal is to perform the translation to
> a "neutral" language before performing any syntax checks. The
> problem with that proposal is that the translation itself must
> involve at least a high level syntax check. For instance, if
> you are programming in Pascal and containing Cobol code, the
> translator could fail.

[OP] Not exactly. I don't think it would be reasonable not to syntax check the source.
Even if it were possible to build a new statement from invalid source imagine trying to
usefully report the cause of the error in a subsequent syntax check (on the converted
code). This may be possible but would likely take a disproportionate chunk of the
programming effort.

Instead, as you hinted, I was thinking about scanning, confirming valid code and
converting to a common form where all computation statements are {operation} {operands}
and operands have three component types, 1) items produced, 2) items consumed and 3) items
modified. (Structure statements such as loops, branches, declarations etc would also be
required.) There would then be a consistent base upon which to build the parse tree, make
it efficient by whatever methods (moving invariant code, factoring formulae, farming out
code to other hardware and the other normal tricks) and being a consistent base for code
to be generated.

The above isn't new (what is?) but where I differ is in that I'm wondering if the syntax
of code could be specified within the source - only at the top unless for masochists! For
example, defining a preferred order for an assembler's operands (it's amazing how some
otherwise very flexible assemblers choose this for the programmer), redefining the
compound statement begin (left brace, {, in C; the word 'begin' in Pascal), the comment
delimiters, how string constants are spcified etc. If this could be done what would stop
this being a translator for any mainstream language and, as you mention, allowing
embedding such as mainly Pascal source to contain some Cobol statements. (Shudders.... I
had to close my eyes as I wrote that - but you get the principle.....)

--
James


Relevant Pages

  • Re: arithmetic in ZF
    ... "Consistent model" is redundant. ... PA is a much more complicated language. ... There is more than one possible translation and it ... You cannot apply "rules of inference" to PA. ...
    (sci.logic)
  • Re: Godels comments about the "true reason" for incompleteness
    ... translation into the language of PA are your referring to? ... prove, then PA is consistent. ... I now see that you are the mother of all formalists. ...
    (sci.logic)
  • Re: Aspects of programming languages in common
    ... A lot of language suites consist of front ends for C, ... My understanding of the proposal is to perform the translation to ... a "neutral" language before performing any syntax checks. ... number in the original source code? ...
    (comp.programming)
  • Re: why this assembly language is not good?
    ... Two things promote a good language: 1) Consistent ... syntax and semantics and 2) Encouragement of a readable format. ...
    (alt.lang.asm)
  • Re: GoTo in Java
    ... The problem with that is that you would never wind up with the example ... as 'language x program' but as a 'language y program in x syntax'. ... that and 'translation' requires 'complete rewrite'. ...
    (comp.lang.cobol)