TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The difference between top-down parsing and bottom-up parsing

81 pointsby zniperrover 10 years ago

8 comments

carsongrossover 10 years ago
I really didn&#x27;t understand grammars until I started doing hand-rolled top-down recursive descent parsing for Gosu.<p>It&#x27;s a shame that parsing in CS schools is taught using theory and lex&#x2F;yacc type tools when a basic lexer and recursive descent parser can be written from first principles in a few months. It is more incremental, and it gives you a much deeper feel for the concepts, plus it lets you learn a bit about software engineering and organization as well.
评论 #8836696 未加载
评论 #8835542 未加载
评论 #8835296 未加载
评论 #8835975 未加载
Guthurover 10 years ago
(facetious-comment &quot;It&#x27;s a tragedy how much brilliance is wasted on grammar parsing when it&#x27;s a solved problem; just use a Lisp&quot;)
评论 #8836749 未加载
评论 #8836638 未加载
评论 #8838287 未加载
nachivpnover 10 years ago
Bottom up parsing - &quot;If not, it&#x27;s necessary to backtrack and try combining tokens in different ways&quot; I feel the way it is put along with shift reduce parsing is misleading. Backtracking is essentially an aspect avoided (more like solved) by shift-reduce parsing. They don&#x27;t go together in bottom up parsing. Shift reduce parsers posses the potential to predict the handle to use by looking at the contents on top of the stack.<p>Good job BTW, there are very few people who write about compiler&#x2F;language theory :)
评论 #8835583 未加载
评论 #8835592 未加载
zuraover 10 years ago
One more difference: top-down parsing is European and bottom-up - American :)
评论 #8835730 未加载
slashnullover 10 years ago
I was so happy when I finally grokked LR parsers: it&#x27;s just a big state machine! _if_ that token found, push on stack, go to _that_ other state. Consume token, check the next state transition.<p>But while fun it was pretty much useless because recursive descents and combinators are so much easier.
评论 #8836205 未加载
vbitover 10 years ago
Another good write-up on this topic is <a href="http://blog.reverberate.org/2013/07/ll-and-lr-parsing-demystified.html?m=1" rel="nofollow">http:&#x2F;&#x2F;blog.reverberate.org&#x2F;2013&#x2F;07&#x2F;ll-and-lr-parsing-demyst...</a>
vorgover 10 years ago
I think I read somewhere incremental parsers are better off being written with bottomup parsers rather than topdown parsers. The reason was that when a small edit is made to the code being parsed, the artifact from a bottomup parser often only needs a minor change that ripples only as far as it needs to, whereas the topdown parser needs to be completely rerun because it can&#x27;t tell whether the effect of one small edit is large or localized. Anyone out there who can verify or refute this?
评论 #8836098 未加载
jimmaswellover 10 years ago
What do you call it if you&#x27;re just using a big list of regexes? I&#x27;ve seen that used for a simple dialog scripting language in a game.
评论 #8838330 未加载