5 ms·
A bottom up parser such as LALR knows what it has built successfully, and knows that the next token makes no sense in the current state. So you have stuff in t
by dbcurtis 8y ago
A bottom up parser such as LALR knows what it has built successfully, and knows that the next token makes no sense in the current state. So you have stuff in the parse stack that is headed somewhere but you don't know where, and you know you are at the earliest point you can detect a syntax error. Unless you rummage around in the parse stack for clues, there really isn't much you can do to make a good message, and the rummaging is often ad-hoc.
When parsing top-down as in recursive descent, you know what higher level syntactic structure you are in the middle of constructing, and anything successfully parsed so far is probably slotted into the AST in a meaningful way, so you simply have a lot more context to go on when constructing a message, and that context is an intuitive AST walk away.