News for hackers. Stuff that matters.
Re:Pratt Parsers: Expression Parsing Made Easy (2011) by DonHopkins on Saturday February 17, 2018 @04:56AM (#16399966)
Vaughan Pratt also designed the Sun logo (an ambigram). But his original design was square, then John Gage rotated it 45 degrees.

https://en.wikipedia.org/wiki/Vaughan_Pratt

https://en.wikipedia.org/wiki/John_Gage

https://orig00.deviantart.net/e290/f/2011/230/2/c/sun_micros...

Re:Pratt Parsers: Expression Parsing Made Easy (2011) by gnufx on Saturday February 17, 2018 @09:42AM (#16400843)
Good point about "if you can do it in Java"... There's a "reprint" of Pratt's paper (of unclear copyright status) at <https://tdop.github.io/>. Classic examples are his CGOL syntax for Lisp <https://people.eecs.berkeley.edu/~fateman/cgol/cgol.1> and Carrette's alternative reader for SIOD as a simpleer example <https://github.com/gjcarrette/siod/tree/master/winsiod>.

I used a variant long ago to implement a command line syntax for Scheme as an extension language. You can modify the dispatch so that juxtaposition acts as application (a pseudo operator with very low precedence) rather than raising an error. That allows mixfix or fully parenthesized forms interchangeably -- possibly with caveats I don't remember -- e.g.

  foo 2*bar*i; baz
probably used at the REPL, reading as the form

  (begin (foo (* 2 bar i)) (baz))
you'd probably use in scripts.
Re:Pratt Parsers: Expression Parsing Made Easy (2011) by jlesk on Saturday February 17, 2018 @05:15AM (#16400018)
Douglas Crockford also has a good article on how to implement Pratt parsing in JavaScript:

https://crockford.com/javascript/tdop/tdop.html

I referenced it often when I implemented THT. (https://tht.help)

Re:Pratt Parsers: Expression Parsing Made Easy (2011) by chubot on Saturday February 17, 2018 @01:24PM (#16401907)
FWIW I review the original article and this one here: http://www.oilshell.org/blog/2016/11/02.html

Index of posts about expression parsing: http://www.oilshell.org/blog/2017/03/31.html

Re:Pratt Parsers: Expression Parsing Made Easy (2011) by jules on Saturday February 17, 2018 @08:42AM (#16400617)
A great article! Here's another one that's a bit shorter: https://eli.thegreenplace.net/2010/01/02/top-down-operator-p...
Re:Pratt Parsers: Expression Parsing Made Easy (2011) by chubot on Saturday February 17, 2018 @01:23PM (#16401901)
FWIW I review the original article and this one here: http://www.oilshell.org/blog/2016/11/02.html

Index of posts about expression parsing: http://www.oilshell.org/blog/2017/03/31.html

Re:Pratt Parsers: Expression Parsing Made Easy (2011) by jopsen on Saturday February 17, 2018 @05:19PM (#16403082)
I recently needed a custom expression language and using a Pratt-Parser to write the interpreter was a joy.

https://github.com/taskcluster/json-e/blob/a0ab770157a5fdb5d...

I wrote up abstractions so you just declare token patterns, precedence ordering of tokens, and infix/prefix rules as mapping from token to function(token, ctx). Where ctx.attempt(...token)), ctx.require(...token) and ctx.parse(precedence) is all you need to implement almost anything.

I didn't get as far as to make it recursive and support multiple grammars. But I'm sure this concept can be made very elegant, without too many tricks.

Re:Pratt Parsers: Expression Parsing Made Easy (2011) by krishanath on Saturday February 17, 2018 @12:41PM (#16401700)
Here's an expression parser, written in C#, that also has the ability to execute the parse tree:

https://github.com/Rajeev-K/formula-parser

Re:Pratt Parsers: Expression Parsing Made Easy (2011) by dukoid on Saturday February 17, 2018 @02:14PM (#16402187)
Here is one written in Java: https://github.com/stefanhaustein/expressionparser

In addition to a simple math expression evaluator, examples include a BASIC interpreter and a simple computer algebra system O:)

Re:Pratt Parsers: Expression Parsing Made Easy (2011) by Sharlin on Saturday February 17, 2018 @03:53PM (#16402626)
I’m on the move so can’t take a closer look right now but I wonder how this relates to precedence-climbing parsers: https://eli.thegreenplace.net/2012/08/02/parsing-expressions...
Re:Pratt Parsers: Expression Parsing Made Easy (2011) by chubot on Saturday February 17, 2018 @07:55PM (#16403776)
This feels like a setup, but:

Pratt Parsing and Precedence Climbing Are the Same Algorithm

http://www.oilshell.org/blog/2016/11/01.html

:)

Re:Pratt Parsers: Expression Parsing Made Easy (2011) by Sharlin on Sunday February 18, 2018 @02:56AM (#16404973)
Thanks! No, I was genuinely curious :)