acornjs / acorn

A small, fast, JavaScript-based JavaScript parser
10.61k stars 886 forks source link

Which parsing algorithm did acorn use when try to parse binary expression? #1094

Closed IWANABETHATGUY closed 2 years ago

IWANABETHATGUY commented 2 years ago

The doc point out that Acorn use perator precedence parser to parse binary expression, I am curious which specific algorithm did acorn use, shunting yard or pratt parser or others?

marijnh commented 2 years ago

It's just a recursive function passing down a precedence value, no idea what that's called.

IWANABETHATGUY commented 2 years ago

Thanks for replying , one more question please. Is it LL or LR?

marijnh commented 2 years ago

The code is right here in the repository. It's a recursive-descent parser, so neither LL nor LR, but more similar to LL.

IWANABETHATGUY commented 2 years ago

Thanks a lot.