[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: language translator help

From: Neil Jerram
Subject: Re: language translator help
Date: 28 Apr 2002 19:21:49 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

>>>>> "Thomas" == Thomas Bushnell, BSG <address@hidden> writes:

    Thomas> "John W. Eaton" <address@hidden> writes:
    >> Thomas Bushnell also suggested generating Scheme forms using cons
    >> instead of writing ASCII text.  Can this be done easily from C for
    >> every language construct?  If so, it seems that it would be easy
    >> enough to switch to this method once the translate-and-emit-text
    >> system works.

    Thomas> Don't use C at all!  My compiler is a Scheme program.

What tools are now available for writing parsers in Scheme?  Last time
we had this conversation on the list, ISTR that there were many ideas
but nothing quite complete.

On the other hand, you (presumably) already have a working parser in
C, and, yes, it should be easy to make it produce Scheme forms
directly from C.  (BTW, I meant generation of Scheme forms before, not
ASCII text.)

I'd expect this to work roughly as follows.  Suppose your parser has a
Bison-like structure and you're parsing a binary operator expression:

 <expr> := <subexpr> <binop> <subexpr>

If $1, $2 and $3 contain previously constructed Scheme forms for
<subexpr>, <binop> and <subexpr>, you can construct the Scheme form
for the whole lot by:

 scm_list_3 ($2, $1, $3);

This assumes that $2 already holds a Scheme symbol, variable or
procedure object.  So, when the token for <binop> was read, you should
have returned the appropriate Scheme object by mapping from the token
string - no big deal there.  The choice between symbol, variable and
procedure is interesting ...

- Using a symbol, say `+', means that the constructed Scheme
  expression will need to be evaluated in a module that has a binding
  for `+'.  Depending on what else you might want to use module
  bindings for, it might be inconvenient for the module namespace to
  include such bindings.  Hence you might prefer ...

- Using a variable means that the constructed expression can be
  evaluated in a module without builtin bindings, but the variable's
  value can still be modified by any code that can get to that
  variable.  In Scheme, for example:

  (define (f)
    (+ 3 4))

  (define + -)

  (f) => -1

  So, should Octave expressions like "3 + 4" be subject to code being
  able to redefine + ?

- Using a procedure means that redefinitions of + won't affect this

It also assumes that $1 and $3 are either lists themselves, or
instances of `Octave data'.  This raises another important question:
how is Octave data represented in Guile?

- At one end of the possibility spectrum, you could define an
  `octave-data' smob type, and handle Octave typing internally inside
  this smob, thus keeping Guile and Octave data completely separate.

- At the other end, you could force as many existing Octave types as
  possible into the nearest available Guile types: floats, uniform
  arrays and so on.  Do the Guile types have sufficient precision for
  you to do this?  Is the uniform array interface convenient?  Etc.

In summary, you can produce Scheme forms for every possible Scheme
language construct from C, and it is pretty easy to do so.  But there
are still lots of questions about exactly what those Scheme forms
should contain.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]