Mailing List Archive: 49091 messages

## [REBOL] Parse versus Regular Expressions

### From: lmecir:mbox:vol:cz at: 3-Apr-2003 9:39

Hi all, sorry, if this is too trivial for the Regular Expressions (RE) experts, I am certainly not one (I am not using RE at all, neither I knew the definition of RE). I've heard, that PARSE was more general, than RE, although I didn't know why. Only recently I found an example: anbn: [#"a" anbn #"b" | none] parse "aaaaabbbbb" anbn ; == true The following is an RE equation ("." means concatenation and "+" means something like or): X = a.X + b , which can be trivially rewritten for PARSE as follows: x: [[#"a" x] | #"b"] and the result: parse "b" x ; == true parse "ab" x ; == true parse "aaab" x ; == true Of course, the result of the RE equation is known, it is ("*" means repetition): X = a*b , which can be rewritten for PARSE as: x: [any #"a" #"b"] , but the fact, that both approaches worked has been appreciated by a local teacher of the subject. Then he asked me, whether the following equation could be easily rewritten for PARSE too: Y = Y.a + b The result of the equation is known, it is: Y = ba* , i.e. in PARSE notation: y: [#"b" any #"a"] Noticeably, the "dumb" approach to the equation rewriting: y: [[y #"a"] | #"b"] didn't "fire" any error, stack overflow, or any unusual exception. Nevertheless, it didn't work: parse "b" y ; == true parse "ba" y ; == false Any ideas? Regards -L