Reflective Scripting

Alex Angelopoulos (aka at mvps dot org)

The unexamined life is not worth living.
Socrates, attributed in Plato's Apology.

I got fairly interested in the idea of using script to parse script last fall.  There is minimal generic parsing infrastructure available for anything on Windows unless you want to delve into Lex and Yacc, but some things are doable.

Parsing VBScript with VBScript is not something which is easy no matter what tools you have; as with any other advanced solution, you may want to wrap script around tools, but the tools themselves should probably be done in something else.

Ira Baxter of Semantic Designs has pointed out to me that some languages do make self-parsing fairly elegant; most notably Scheme.  Semantic Designs does have its own VBScript parser, by the way.  I don't tend to recommend anyone's solutions in particular for any problem, but I can offer some opinions about Semantic Designs and this particular product.  The principals in the company understand the issues behind code parsing and factoring; their specialization dates back to their Ph. D. work.

Groping Around Parsing

While trying to figure out how to tackle this problem, I made a number of posts to the microsoft.public.scripting.* hierarchy about this; here's a link to the Google archived posts.

Script Parsing Code

I came up with some code to handle special cases.


This script takes the path to a WSC as an argument, and returns the following information to standard output: the ProgID for the component, followed by counts and names of each property, event, and method exposed within the WSC.


This was actual motivation for the script above; it is a WSC which encapsulates most of my work on parsing VBScript code.

Other Tools

The Gold Parser Builder

Devin Cook's Gold Parser Builder is an interesting tool, particularly since it is COM-accessible.  I've assembled some short notes on the parser for my own use.