Your skill will accomplish
what the force of many cannot
Parsing a macro languageby bluetrust (Novice)
|on Jul 08, 2005 at 22:41 UTC||Need Help??|
bluetrust has asked for the
wisdom of the Perl Monks concerning the following question:
Ahoy Perl Pirates,
I'm having trouble figuring out how to convert a macro language into a data structure for processing.
The macro script looks like this:
(It's for writing questionnaires.) There's an awful lot of nesting going on.
I was thinking that the exercise would be simpler if we processed the script by searching for the macro grammar patterns:
The in-memory data structure for processing it is all up to me, but I was thinking that it would probably look something like this in the end:
How on earth would you go about converting one to another?
I've looked into Parse::RecDescent and it seems to be ideal, but it's a complicated module and none of the tutorials I've looked at have an example dealing with nested grammar. If I could get it to work though, it looks like it would be easier to extend than the other solutions I had in mind involving a loop and either a regular expression for finding childless blocks -- or a floating reference that moves up and down the data structure as we process each line. (I've done those sorts of things before, and the code was always unreadable afterwards.)
What do you think, mateys?
Is there a simple solution to this?