[clean-list] Please answer this parsing question

metaperl metaperl at gmail.com
Thu Aug 28 15:53:01 MEST 2008




terrence.brannon wrote:
> 
> (&>) is right associative:
> // and-combinator that only retains the right hand side result
> (&>)	infixr 6 // :: (Parser s r t) (Parser s r` t) -> Parser s r` t
> (&>) p1 p2 :== p1 <&> const p2
> 
> 
> So when I read this expression:
> p =  twoDigits &> twoDigits &> (<!?> twoDigits undef undef) &> (symbol
> 'Z')
> 
> I should rewrite it to this:
> p =  ( twoDigits &> ( twoDigits &> ( (<!?> twoDigits undef undef) &>
> (symbol 'Z') ) ) )
> 
> But then I get confused about order of execution...
> won't the innermost parenthetical expression execute first and the parse
> will attempt to execute this first:
> ( (<!?> twoDigits undef undef) &> (symbol 'Z') ) 
> 
> Which would not be the desired parsing order.
> 
> 

I am right about what right-associativity does to an unparenthesized
expression <http://en.wikipedia.org/wiki/Associative#More_examples>

So the question becomes: isn't the first function which attempts to "eat"
the input string (symbol 'Z')

But I think the input string is supposed to be parsed from left to right. So
that is undesirable behavior.
I would think left-associativity would be more preferred.



-- 
View this message in context: http://www.nabble.com/understanding-a-right-associative-parser-combinator-tp19165664p19201044.html
Sent from the Clean mailing list archive at Nabble.com.



More information about the clean-list mailing list