http://www.perlmonks.org?node_id=548588


in reply to A simple list oriented language in Perl

When designing and implementing a new language, it is best to start by creating a grammar for the elements in your language, keeping in mind the semantics of each element as you go along.

For instance, your assignment might take on the form

<assign> =: <assign-token> "->{\n" <assign-list> "}\n" <assign-token> =: "\w+" <assign-list> =: <assign-element> <assign-list> | (null) <assign-element> =: "[0-9]+\n"
where nonterminal elements are in <> and literals and regexes are in "".

Once you have created a grammar you can implement it using Parse::RecDescent or your own recursive desecnt set of routines. Once you have the parser working, you can begin to create the translation routines.

Programming macro languages can be a bit tricky due to expansion rules. What gets expanded when? How do I quote expressions to prevent expansions? And so on. Two good examples of macro languages that deal with these issues are m4 and TeX. Both have good documentation.

-Mark

Replies are listed 'Best First'.
Re^2: A simple list oriented language in Perl
by blazar (Canon) on May 11, 2006 at 12:22 UTC
    Programming macro languages can be a bit tricky due to expansion rules. What gets expanded when? How do I quote expressions to prevent expansions? And so on. Two good examples of macro languages that deal with these issues are m4 and TeX. Both have good documentation.

    In fact TeX itself is even in the opinion of very knowledgeable TeXperts, a real mess. See for example David Kastrup's posts in this thread (also available from Google Groups).