In my copious spare time™ one of my passions is weaving. Last week a notice appeared on one of the weaving lists, posting a url of:
http://www.cs.arizona.edu/patterns/weaving
In particular was an article entitled "The Painter Weaving Language" by Ralph Griswold. Here is a link to the file: The Painter Weaving Language.pdf Professor Griswold mentions the user document from Corel, in the bibliography Weaving.pdf it also is a useful read. Ralph was (he died on October 4, 2006) the keeper of the site and the inventor of Icon and Snobol as well as being an expert weaver. At any rate, the article rang a bell as I remembered that I had stumbled across this feature sometime before and had intended to write an expression evaluator for same in Perl, but had gotten distracted by the real world™!
Armed with Ralph's article and the original document I went ahead and created weave.pl
.
While this particular program produces results that are at best only of esoteric
interest to most Perl programmers, the code that is used is easily converted to handle
expressions from any small language.
lex
to translate the initial expression into one with uniform keywords.expression2list
.parenthesize
.list2expression
.innermost
.To generalize this code, the precedence table found in expression2list
would have to either be passed or become global to the function and lex
would have to be rewritten to handle the details of the given implementation's keywords.
For compiler junkies, the routine called parenthesize
is in implementation of
John A. N. Lee's chapter 6, 'Source Text Manipulation', section on 'Parenthesizing
Expressions', page 267 of The Anatomy of a Compiler, second edition.
And for you string (the computer kind, not the weaver's kind) junkies out there, Ralph has also written articles on creating weaving patterns using both L-Systems and Cellular Automata! Enjoy!!
For anyone curious about what such software can produce, here are some images created by some of the included scripts: