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
where nonterminal elements are in <> and literals and regexes are in "".<assign> =: <assign-token> "->{\n" <assign-list> "}\n" <assign-token> =: "\w+" <assign-list> =: <assign-element> <assign-list> | (null) <assign-element> =: "[0-9]+\n"
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 |
In Section
Seekers of Perl Wisdom