Hi Gary,
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. While
M4 is theoretically powerful enough to do so, experience has shown me that it
hurts in the long run. 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), but: after you have solved your syntax
issue your development will become painful for two reasons:
1) as your substitution rules become more and more complex (you *will* want to
add more and more features to your toy language), they will become gradually
less maintainable
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.
Why not slapping a proper parser in your favorite functional language (Python,
Haskell, whatever) and then celebrate the joys of high-level program
transformation? You can ping me offline if you want some pointers about this.
--
Raphael 'kena' Poss · [email protected] · +31 20 525 8707
UvA · FNWI · IvI · CSA · 1098XH 904 Amsterdam (NL)