From: Mathieu Bouchard Date: 2001-06-11T14:39:35+09:00 Subject: [ruby-talk:16400] Symbolic Computation III This third installment departs from the former two [ruby-talk:16383], [ruby-talk:16387] in a major way. Those two were just play-dough to get started. Why play with Ruby numeric exprs when you could deal with the whole source code? Now I'm going to request the attention of: Ruby-in-Ruby parser folks, Ruby-in-Java interpreter folks. There needs to be a interface between a parser and an interpreter. Often it's an AST system or a bytecode system. Matz has chosen the AST way with his Ruby interpreter. Now our job is to make something similar to Matz' AST system. But I want it like this: 1. It has to be expressed in Ruby, not in C. 2. *All* parser details go in the parser. 3. *All* interp details go in the interp. 4. The AST system must be a common middleground that allows for writing parsers, unparsers, interpreters, compilers, decompilers, optimizers, analyzers, refactorers, classbrowsers, obfuscators, deobfuscators, highlighters, lintcheckers, indenters, whatevers. 5. It Must Make It Simple. I mean Simple. That's Simple to read, understand, recite, encode in, decode out, process, transform, use in a contorted fashion, use in an unintended fashion, extend, modify, rewrite, extend, hack, butcher. Now to satisfy all of that at once it should do its job, it should not do others' job, it should allow others to do their job, there should be nothing to add, and nothing to remove. This is my kind of Simple. 6. Therefore: 6.1. It shall be to Ruby source what DOM is to XML. 6.2. Structure of valid Ruby trees shall be expressed as a schema: basically, a few dozen classes. 6.3. That schema should contain less rules than Matz' AST system. 6.4. Meta-types (Struct/Tuple, Choice, Array/List, Union) shall describe how the schema is built (naming and typing), what it means, and provide means to verify validity (as structures are created/modified, or in a single pass when request, at choice). 6.5. Parsers will build such trees; interpreters, compilers, will read them; optimisers will modify them; indenters will traverse them and follow the annotations. I am publishing a rough draft that is as broken as are any of my first releases (see ArrayMixin/MetaRuby, RubyX11). That's called "pseudo-code" as in "It Doesn't Work (yet)". Even worse, it was loosely translated from Ruby 1.4 pseudo-BNF grammar. So you are warned. (the version I gave out on IRC was 0.0) http://hostname.2y.net/~matju/MetaRuby/RubyAST-0.1.rb matju