lua-users home
lua-l archive

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


On Aug 9, 2005, at 13:42:59, Boyko Bantchev wrote:
  Don't worry, he's talking about a programming language:

http://en.wikipedia.org/wiki/Brainf%2Ack

I know.

I guessed so, but I was actually trying to console Klaus, who seemed to be seeing the mention of brainfuck as an insult. From his later replies I suppose he knew the language and still considered it an insult. I actually think brainfuck is a very clever and cool language. Especially since it is very easy to write a parser, compiler and/or interpreter for it. That doesn't keep me from not wanting to have to program in it, though ;-)

But I was actually serious about the preprocessor I described,
I do use it and find the style of writing convenient.  Making fun is
ok, but I was hoping to also provoke some exchange of opinions
on this.  Can't believe that absolutely noone is interested in such
a discussion.

I've seen enough people try to write such "language translators" using simple search/replace patterns or regular expressions. Most of them got pretty far, than realized that they wanted to do more than this solution would allow. As you seem to be using the same technique (at least that's what some of your statements sounded like to me), I didn't really have much hope for this getting anywhere.

The difference between a Macro processor and a compiler is that a preprocessor has a very limited parser. It's usually concerned with symbolic constant substitution and conditional compilation, and not much else. For that, search and replace works just fine. For anything more, you'll typically need a full-blown parser, and once you're there, you might as well just replace Lua's parser and get rid of the middleman to just deploy to the same byte-code format.

I personally am from the opposite camp than you are. I prefer really verbose and english-like languages. Therefore, I guess you'll understand that while I respect the craftsmanship, I'm not really too much interested in your translator. :-/ If you wanted to create a new parser on top of Lua, though, I might be interested in helping with the front end/back end separation, though. After all, that would let me replace the parser with one of my own, verbose ones.

In this respect, could Lua be used as a
preprocessor to itself?  Especially since Lua can compile &
execute Lua code?  Perhaps some form of a `syntax
bootstrapper'?  PL/I, in its time, had a preprocessor that was
more or less PL/I itself.  But these days preprocessors seem
not to be in fashion.

Lua definitely seems powerful enough for me to write a Lua compiler in. And an interpreter. Once you have those, you could certainly use Lua to compile itself. But IMHO that would hamper Lua's portability. ANSI C already has been ported to most platforms, and lua and luac compile beautifully that way. Bootstrapping would mean we'd need to write native-code compilers for each platform Lua should run on... The approach is cool from a technical point of view, but would sadly be impractical. Of course, the preprocessor could be written in Lua.

Cheers,
-- M. Uli Kusterer
http://www.zathras.de