[REBOL] Re: [REBOL parse] Parsing AEIOU and sometimes Y
From: santilli:gabriele::gmail at: 2-May-2007 12:18
2007/5/2, Anton Rolls <anton-wilddsl.net.au>:
> Hi Ed,
>
> Here's my go at it:
[...]
Looks like a state machine to me.
vowel: charset "aoeuiAOEUI"
y: charset "yY"
consonant: exclude charset [#"b" - #"x" #"z" #"B" - #"X" #"Z"] vowel
start: [consonant after-cons | vowel after-vow | y after-y | end]
after-cons: [consonant after-cons | vowel after-vow | y after-cy | end]
after-vow: [consonant after-cons | vowel after-vow | y after-vy | end]
after-y: [vowel (print "y = consonant") after-vow | consonant (print
???
) after-cons | end (print "???")]
after-cy: [consonant (print "y = vowel") after-cons | vowel (print "y
= semivowel?") after-vow | end (print "y = vowel")]
after-vy: [consonant (print "y = semivowel?") after-cons | vowel
(print "y = consonant") after-vow | end (print "y = vowel")]
Note, since this implementation in recursive, it is not usable to
parse long text. It is easy to make it non-recursive though, although
it may be a bit less readable.
(Another approach for better readability may be to use a FSM
interpreter like mine: http://www.colellachiara.com/soft/MD3/fsm.html
)
HTH,
Gabriele.