|laziness, impatience, and hubris|
Re: Parse::RecDescent for simple syntax-directed translationby Limbic~Region (Chancellor)
|on Jun 18, 2006 at 15:16 UTC||Need Help??|
(This is the "classic example" of something that can't be done with regular expressions, 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). Anyhoo...)
While this is probably strictly true, Perl is all about letting you get the job done:
Anyhoo...I have just recently started learning Parse::RecDescent. Update: I am not sure if this is what you had in mind, but the following accomplishes what you want without using sneaky experimental regex features.
A lot of this code could be simplified and improved. I am neither a regex nor Parse::RecDescent guru. I did show how either could work.
Once you have a string of a's followed by one or more b's ($item), you only needed to calculate the desired string and assign it to $return. An explicit assignment to $return is not necessary as you could just let the last expression be returned as with Perl's subroutines.
Cheers - L~R