Skip to content

Latest commit

 

History

History
66 lines (55 loc) · 2.88 KB

readme.org

File metadata and controls

66 lines (55 loc) · 2.88 KB

MetaII

./img/penrose.gif

1 What

This is my implementation of Schorre’s metaII metacompiler using perl5 regex’s for bootstrapping and compiling to lua (using http://loup-vaillant.fr/projects/metacompilers lua’s model). Articles abut the implementation and random ramblings also in my blog.

2 Why

Reading about metacompilers I’ve tinkered with them on and off for a couple of months, taking off from loup’s implementation, but when I was reading perlre, I rediscovered the (?{}) extended pattern, which basically does the same as metaII ouptut patterns, so I tried to bootstrap a metaII compiler using recursive regular expressions and (?{}).

3 Why should I care?

Take a look at ./bootstrap.txt , and if you don’t find that a piece of self-reference beauty, you probably shouldn’t care at all.

4 Curious to note from the code:

4.1 Recursive regexes in perl can call themselves.

Or call undefined regexes at compile time: Instead of directly calling them by name, you have to wrap them into (??{our $regex}) to delay the evaluation to runtime.

4.2 /x flag in regex is invaluable in this case.

4.3 Perldoc

Perl has by far the best documentation I’ve read for any programming language. Fun to read, useful and pragmatic at the same time. Take a look at Backtracking to see a great explanation of backtracking behaviour in regexes.

4.4 Special vars in Perl regexen.

$[1-9] get reset after a complete regex has ben matched, but not during the matching. If you need to match the latest match in this very same regex, use $^N. Use a stack in case of nested regexes needing the ‘latest match’. More regex wizardy in “Parsing JSON with a single regex”: https://www.youtube.com/watch?v=-O-Uajd2WzU

5 See also

6 Who