develooper Front page | perl.perl5.porters | Postings from January 2018

Re: We need a language design process.

Thread Previous | Thread Next
Paul "LeoNerd" Evans
January 16, 2018 01:01
Re: We need a language design process.
Message ID:
On Sun, 7 Jan 2018 16:01:25 -0600
David Nicol <> wrote:

> came *really* close to providing the proper kind of hook I was
> looking for, when my Macrame project encountered the limits of the
> naive parser in Filter::Simple. I couldn't quite make sense of the
> invocation mechanisms though.
> In general, the macro keyword would be sugar for introducing the new
> syntax; keeping consistent with the LALR parser makes circumfix
> macros (for some reason that seemed like an essential feature) even
> trickier -- when the closing token is not found within the
> compilation unit the tokens need to get returned to the token stream
> or the pointer backed up, or something -- complicated
> I don't remember.
> It seemed like a possible way forward would be to ditch YACC entirely
> and restate the actual language parsing in Perl -- towards this end I
> did reverse-engineer some state diagrams -- it seemed like after
> doing the extensive research exercise of actually delivering Perl
> parsed by Perl, the things that could be simplified into macros might
> become apparent -- for instance all the various loops could be
> formally normalized into c-style for loops by macros.

I was going to go a far simpler strategy.

Each "macro" would be a Scheme-style combination of

  * a template to guide the parser in how to cut out the invocation of
    that macro from the source code into one or more variable body

  * a substitution parametrised in the pieces cut apart by the
    template to act as the macro's replacement.

I've no idea exactly what form the eventual would look like, but the
idea was to specify the template "somehow" so the parser can slice up
the incoming syntax into optree pieces, and pass those as arguments
into a normal perl function that acts as the substitution. For example,

  sub twice :MACRO(EXPR)
    my ($expr) = @_;

    return Optree->seq($expr, $expr);

  twice say "Hello, world";

I haven't at all looked into how that would work in practice though so
there may be all sorts of problems with it, but that was the rough
overall shape I had in mind.

Paul "LeoNerd" Evans      |  |

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About