Home

Survey of Expression Parsing Algorithms in the Wild

2017-03-28

Shunting Yard Algorithm

Norvell Article also leads to it

Bottom Up Methods

Pratt parsing and precedence climbing are both http://eli.thegreenplace.net/2009/03/20/a-recursive-descent-parser-with-an-infix-expression-evaluator/

Survey

I sent this to someone.

TODO: Send me links to how your favorite programming language does it! I will put them here.

Or edit the Wiki:

Which should I Use?

Hand-written or generated?

If hand-written, top-down or bottom-up?

Pratt Parsing is easiest.

They are all kind of the same?

For reference, here are two articles on other methods for

Other articles:

For example, here's expr.c in bash. You can see from these function prototypes that it uses plain recursive descent to encode precedence. This works fine, but results in more code, and in theory it's less efficient. Processing a single token requires making make dozens of function calls.

static intmax_t expcomma __P((void));
static intmax_t expassign __P((void));
static intmax_t expcond __P((void));
static intmax_t explor __P((void));
static intmax_t expland __P((void));
static intmax_t expbor __P((void));
static intmax_t expbxor __P((void));
static intmax_t expband __P((void));
static intmax_t exp5 __P((void));
static intmax_t exp4 __P((void));
static intmax_t expshift __P((void));
static intmax_t exp3 __P((void));
static intmax_t exp2 __P((void));
static intmax_t exppower __P((void));
static intmax_t exp1 __P((void));
static intmax_t exp0 __P((void));


Discuss this post on Reddit.
Get notified about new posts via @oilshellblog on Twitter.