|Problems? Is your data what you think it is?|
Parse::RecDescent for simple syntax-directed translationby tomazos (Deacon)
|on Jun 17, 2006 at 15:47 UTC ( #555986=perlquestion: print w/replies, xml )||Need Help??|
tomazos has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to work out how to use Parse::RecDescent and am a little overwhelmed.
I can see how to use it as a recognizer, but to do a simple syntax-directed translation, all of the *items, $return, $text, real return value, etc, stuff has thrown me off.
Let's say you want a translator for languages over ('a','b','c','d','e') such that any balanced pairs of equal length sequences of a's and b's are replaced by c's and d's.
(Side note: This is the "classic example" of something that can't be done with Update: regular grammars, and needs a context-free grammar. This is because within the regexp /(a*)(b*)/ there is no way to assert that length($1) == length($2).)
The syntax-directed translation (in pseudo-code) would be:
Any ideas on how this translates into Parse::RecDescent? Is there a more appropriate parsing module to use for cases where the input language is very similiar to the output language?
Back to Seekers of Perl Wisdom