in reply to Re: Many birds, single cage...
in thread Many birds, single cage...

Dear duff
Thank you, but I have near 50 capture parentesis on my real regular expression. It is a complete grammar for my company's application command-line parser. This was the first solution I tried and rejected, because it's unacceptable (and what if I need one more capture parentesis?).

Thank you for the effort and for care about answering, anyway. This for sure will be usefull for another monk, in the future.


"In few words, translating PerlMonks documentation and best articles to other languages is like building a bridge to join other Perl communities into PerlMonks family. This makes the family bigger, the knowledge greather, the parties better and the life easier." -- monsieur_champs

Replies are listed 'Best First'.
Re: Re: Re: Many birds, single cage...
by mr_mischief (Monsignor) on Dec 09, 2003 at 22:42 UTC
    If it's a complete grammar, then somethign like Parse::RecDescent or another parser generator may be a good bet for future development.

    You can do it all with regular expressions and captures, but I'm not sure why you would want to.

    If a proper parsing module is not an option, you could match one token at a time in a loop. From there you could build a recursive descent parser of your own or somesuch.



    Christopher E. Stith

      Fellow mr mischief
      I've never ever used Parse::RecDescent before. It worth the effort? The documentation is pretty big, seems that its a big and complex module. Except by some more regular expressions spread through the code, I'm basically using this as my "parser" (sorry about the portuguese comments, I can translate them on demand):

      I would love to read what the fellow monks think about this code, and if someone have any nice way to improve it. Thank you all for the answers and considerations, and may the gods bless you.


      "In few words, translating PerlMonks documentation and best articles to other languages is like building a bridge to join other Perl communities into PerlMonks family. This makes the family bigger, the knowledge greather, the parties better and the life easier." -- monsieur_champs

        If your program, with the chances suggested before, works for all cases and will never or very seldom need to be changed, then it's probably not worth pulling out a big powerful tool like a parser generator module.

        If it's likely to change much, even a little at a time, then eventually you'd have saved more and more work in the end by moving to using one. It's all a matter of cost versus benefits.

        If everything works and never needs to be changed, then the cost of rewriting the code to use another tool is wasted effort with no real up-front benefit. If someone needs to maintain it, then the costs add up over time either way and the benefits of having a cleaner implementation become more pronounced.

        BTW, I've had enough French and Spanish and your comments are written clearly enough that I get a good understanding of them, although I wouldn't be able to rewrite them en Portugues. Yet another example of why clear comments are helpful -- non-native readers have a massively better chance of making sense of them.



        Christopher E. Stith