Re: Generating loops

Gary <[email protected]>
Newsgroups gmane.comp.gnu.m4.general
Message-ID <[email protected]>
Raphael 'kena' Poss wrote:
> Op 21 sep 2010, om 12:53 heeft Gary het volgende geschreven:
>
>> I should say, I'm not married to this syntax. If something else is
>> easier to process then as long as it is readable as a "for" construct
>> I'm not fussed.
>
> It looks like you are tempted to use M4 to implement a compiler of
> sorts.

Err, no :) I am (atually, "we are" - I'm not the only one) just
unfortunate enough to sometimes have to write code in a language which
isn't fit to call itself a language. Source to source translation is as
much as I want, and only for a couple of small things like missing loop
constructs (having to sit and manually write them using those gotos is
just a PITA).

I looked at antlr but given the scope of what I want to do it was
complete overkill in terms of the work involved. At that point I wanted
to be able to write C - so I could not only write code in a meaningful
language but also have some tool support as a result - and generate the
target script code from that; I haven't abandoned that idea entirely,
but kind of need something that will give me results more quickly, even
if the results are less far reaching.

The other stuff I posted about over the last couple of days is a
completely different subject, I just see an opportunity to unify the
tools used.

> Actually I am involved a project which more-or-less does what you are
> doing (the syntax to solve your problem could be "for(i, 1, 12)"
> instead of "for i = 1 to 12" like in C)

That would work. Actually I was hoping to be able to redefine whatever
"," is called to be " " or something (like one can with comments and
quote marks).

> 1) as your substitution rules become more and more complex

It's not *my* language. I'm offended! ;) But "toy" is being generous. Or
do you not mean the target language?

> (you *will* want to add more and more features to your toy language),

If you mean the target language, I can't. If you mean the "language"
that m4 would translate... well, you might be right :">

> 2) there are transformations that are non-trivial to perform with M4;
> say for example you want to define a syntax like:
>
>     PREFIX(f, g, h) code... SUFFIX
>
> and you want this to expand to:
>
>     f(code...)  g(code...)  h(code...)
>
> or anything of the kind where the same piece of input code is
> processed multiple times in different ways, your M4 code will quickly
> become unreadable.

Unreadable? I can't even write it :))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.