Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Parse versus Regular Expressions

From: joel:neely:fedex at: 4-Apr-2003 17:01

Hi, Ladislav, Ladislav Mecir wrote:
> As I mentioned here, it is: > > z: [#a z #b | none] > > , which is a rule, that cannot be written using Regular Expressions. >
OK. The old context-free-vs-context-sensitive thing. However, this little example doesn't scale up very well AFAICT. An equivalent to parse somestring z: [#a z #b | none] in Perl would be something like $somestring =~ /^(a*)(b*)$/ and length ($1) == length ($2) While the content identification and the length equality take two different sub-expressions, I'm wondering what happens if we make the problem just a little larger, and try to match any of "" "abc" "aabbcc" "aaabbbccc" and so on. Using an RE to get content, and then checking lengths, is easy to write and understand (and the pattern scales up to more than two pieces of content), as follows: $somestring =~ /^(a*)(b*)(c*)$/ and length ($1) == length ($2) and length ($2) == length ($3) and so on for four or more "pieces". How would you attack that with the PARSE dialect? -jn- -- ---------------------------------------------------------------------- Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446 Counting lines of code is to software development as counting bricks is to urban development.