155 points · by implmentor · 10y ago · 35 comments
Unfortunately, given the extremely limited hardware of 1960s computers (not helped by the lack of an efficient algorithm), the parsing of an arbitrary CFG was too slow to be practical. Parsing algorithms such as LL, LR, and LALR identified subsets of the full class of CFGs that could be efficiently parsed. Later, relatively practical algorithms for parsing any CFG appeared, most notably Earley's 1973 parsing algorithm. It is easy to overlook the relative difference in performance between then and now: the fastest computer in the world from 1964-1969 was the CDC6600 which executed at around 10 MIPS; my 2010 mobile phone has a processor which runs at over 2000 MIPS. By the time computers had become fast enough for Earley's algorithm, LL, LR, and friends had established a cultural dominance which is only now being seriously challenged - many of the most widely used tools still use those algorithms (or variants) for parsing. Nevertheless in tools such as ACCENT / ENTIRE and recent versions of bison, one has access to performant parsers which can parse any CFG, if that is needed.
from: http://tratt.net/laurie/blog/entries/parsing_the_solved_prob...
Featured here 6 years ago: https://news.ycombinator.com/item?id=2327313
I'm happy to answer any questions about it.
Was this article ever written?
Maybe the thing to do is to illustrate a few of the most basic algorithms by example, just to give people a taste of what they look like.
In other words - how did you get to know them?
<plus>1<times>2 3</times><plus>
Great article, though! </plus>But actually, I did read this excellent article for the second time. However, unless you are skilled in the art, you should be using ANTLR4, Honey Badger. Terence Parr deserves a Turing award.
For parsing, most upper div compiler classes start off with CFGs, dip briefly into LL recursive descent and then conclude with LALR. If people remember anything, it's SHIFT/REDUCE. Unfortunately, there doesn't seem to be any standard tools for the LL(1) equivalent, FIRST/FOLLOW tables. And as the article shows, they aren't equivalent. Each has strengths but LALR has tools.
Except for ANTLR. Which started out as recursive descent ...
Parsing Techniques doesn't really have any competition. The compiler books, like the compiler classes, can only give a little attention to parsing. Given how strong the available tools are and how hard the remaining subjects are (SSA, code generation, ...) maybe they have a point.
I find recursive descent parsers are easy to understand, write, debug(you can drop in a breakpoint a follow it through), and the resultant code is actually readable and clean. It's also fairly easy to add error reporting and recovery. As long as you don't do complicated stuff, they're really fast to.
You don't particularly need to be an expert to write recursive descent parsers either.
The last few time when I've been working on programming language prototypes, I've written the parser using Parsec parser combinators in Haskell. It's super fast and easy to use, however it's more like syntactic sugar for recursive descent parsers than a rigorous parser generator that works for a certain grammar class.
Bison and Flex are available as apt packages on Ubuntu and there is heaps of documentation.
The Ruby angle means you don't have to roll your own AST structures. Also, Ruby's 'VALUE' type is easily passed around in Bison grammar.
example:
https://github.com/cjhdev/slow_blink/blob/master/etc/slow_bl...
There is a learning curve with lex and yacc but if you cannot ever use these programs then what can you really call yourself a programmer?
It's the endless search for a "new" programming language and the layers upon layers of needless abstraction created by today's "programmers" that I find mystifying.