Hi Mark, Brilliant work, thank you! I was playing with your arithmetic parser from tutorial, and noticed the following definition for add and sub:
"expr = add-sub <add-sub> = mul-div | add | sub add = add-sub <'+'> mul-div sub = add-sub <'-'> mul-div ... And I realize now that the ordering "add-sub <'+'> mul-div" here is very deliberate. What should be my intuition for your parser for default ambiguity resolution rules? (sorry, I'm not familiar [yet] with GLL parsers) Is it guaranteed to be non-greedy, i.e. it consumes as little as possible? The docs section "No Grammar Left Behind" is somewhat fuzzy about it. If I were writing LALR parser I would do (along with defining precedence and associativity rules for op) something like: expr = expr op expr | ... And for LL parser I would do: add = mul-div <'+'> add-sub (i.e. reverse ordering compared to yours). But your parser rules are somewhat new to me. Both variations are accepted: add = add-sub <'+'> add-sub add = mul-div <'+'> add-sub And in both cases some generated parsers are correct (arithmetically speaking :-) ), but I'd like to understand rules for the first/default parser. Could you clarify it a little please? Great docs, BTW. Thanks, Dmitry. On Monday, April 8, 2013 10:18:39 PM UTC-7, puzzler wrote: > > Instaparse is an easy-to-use, feature-rich parser generator for Clojure. > The two stand-out features: > > 1. Converts standard EBNF notation for context-free grammars into an > executable parser. Makes the task of building parsers as lightweight and > simple as working with regular expressions. > > 2. Works with *any* context-free grammar. This means you don't have to > learn the esoteric subtleties of LR, LL, LALR or any other specialized > subset. Left-recursion, right-recursion, ambiguous grammars -- instaparse > handles it all. > > Example: > > (def as-and-bs > (parser > "S = AB* > AB = A B > A = 'a'+ > B = 'b'+")) > > => (as-and-bs "aaaaabbbaaaabb") > [:S > [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]] > [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]] > > https://github.com/Engelberg/instaparse for full feature list and > extensive tutorial. > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.