Hacker News new | ask | show | jobs
by mrkeen 500 days ago
> It seems as if you're trying to explicitly instruct a top-down parser.

My mistake, that didn't even occur to me! I only ever use parser combinators so I just read grammars as if they were the code, and vice-versa.

e.g. you could implement the grammar on the upper line as the code on the lower line:

  S -> F  |   F          +     S
  s  = f <|> (f >> char '+' >> s)
The two grammars you posted both 'look good' just by eyeballing them, neither needs 'fixing' (per the article title). They have identical precedence and identical don't-recurse-infinitely properties.
1 comments

A grammar is not the language. A language can be described by infinitely many grammars. That also goes for precedence. Parsing theory describes which algorithms can handle which grammars, and how efficiently they can do that. It allows you to ignore the details of parsing.