lua-users home
lua-l archive

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


On 07/03/11 09:54, Alex Bradbury wrote:
> On 7 March 2011 09:29, Axel Kittenberger <axkibe@gmail.com> wrote:
>> Sure it can for you, but on a global "can lua replace awk", I'll say
>> no. First awk is a quasi-standard, that is you can always asume it be
>> installed on any *nix machine
> 
> Even better than quasi-standard:
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html

Hrm.

Many years ago, when I was younger and a lot more stupid, I wrote a
compiler in awk --- a full recursive descent compiler with types for a
simple bytecode-based VM. The awk version was the bootstrap compiler and
was about 1600 lines of code.

awk is a really simple but slightly elegant language --- you can do a
suprising amount in it for a language that doesn't even need a garbage
collector! But the existing implementations are painfully slow; gawk is
horrible, and the de factor default installation, mawk, is only a bit
better.

So it occurs to me it's probably possible to programmatically translate
awk scripts into Lua and run them on the Lua VM (with optional JITing).
With luck the result ought to be quite a lot faster. It would depend
heavily on a decent regex library, of course. The ability to trivially
extend awk scripts by adding Lua code to interface to the outside world
could well be valuable to people with a large awk codebase.

(If anyone cares, look at http://www.cowlark.com/mercat/ and it's
com.awk inside the 'core' package. I eventually gave up when, after
considerable effort, I ported the bootstrap compiler into my language
and discovered that the awk version was substantially faster...)

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "Thou who might be our Father, who perhaps may be in Heaven, hallowed
│ be Thy Name, if Name Thou hast and any desire to see it hallowed..."
│ --- _Creatures of Light and Darkness_, Roger Zelazny

Attachment: signature.asc
Description: OpenPGP digital signature