This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: difficulty of writing translators


Maciej Stachowiak writes:

> Perl has fairly nice semantics but a hideous syntax. I can only
> imagine parsing perl by using the exiting perl parser. Reimplementing
> that code in a bogosity-compatible, er, I mean feature-compatible way
> would be pretty hard.

It might be easier to start by writing a Perl-bytecode-to-Scheme
translator.

You'd still have to do namespace management; in Perl, `*foo' is a
scalar, a hash table, an array, a procedure, a port, a symbol, and (I
think) a "format", and `*bar = *foo' aliases them all at once.  This
shouldn't be hard to translate in a hackish way; to do it elegantly
and efficiently will require genius. (and perhaps a fortuitous new
module system implementation)  If this issue is solved, the Exporter
(one of the two really hard-core standard library modules, the other
being Carp) should come almost for free.

To translate both Exporter and Carp "out of the box," we would need a
way to translate Perl's `caller' operator.  This is essentially a way
to examine all current stack frames to find function names (lambdas
would translate as `__ANON__', though it would be nice if not all Perl
subs appeared nameless in Scheme), source file, and line number.  I
haven't tinkered enough with Guile to be sure, but I imagine this
stuff is already Scheme-accessible or can be easily made so.  I don't
know if any though has been given to the equivalent of `#line'
directives in x-to-Scheme translation, but in any case the issue is
not unique to Perl.

We'll probably want a dynamic hash table implementation... not sure
how this mixes with gc.  In the same vein, resizable vectors or the
like would be nice for implementing Perl arrays.

Supporting Perl's FFI might be hard.  It might be easy if programmers
have stuck to using the documented API, but I for one haven't always
done so. (evil grin)

But to come back to the point that seems to repel everyone from the
thought of a Perl translator: yes, Perl syntax is about as complex as
natural language (mild exaggeration).  Version 0.0 of a translator
would probably use the bytecode compiler or a C module linked with
libperl for the initial pass.  The positive side is that Perl is an
extremely flexible language, easily capable of interfacing to Scheme
in a natural and friendly way.

-John