TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How Desmos uses Pratt Parsers (2018)

99 点作者 vector_spaces将近 2 年前

4 条评论

awhitty将近 2 年前
I once mentioned Desmos to a college friend who was teaching high school math. This was the first and one of the only times I’ve seen someone express true glee about a software product. They literally shouted, “I love Desmos!” at the dinner table. Kudos to the team for building a product that teachers love that much. Teachers need all the help they can get.<p>I’m so curious about how their graphing calculator and their geometric construction tools work. I’ve spent marginal amounts of time researching their stack, and it appears to be custom software. If anyone’s familiar with writing about how these systems are built (particularly the display side of things), I’d appreciate some links or titles!
评论 #36249810 未加载
评论 #36248685 未加载
评论 #36249600 未加载
DonHopkins将近 2 年前
Vaughan Pratt (who directed the SUN workstation project at Stanford from 1980 to 1982) is the genius who designed the origin Sun Microsystems logo. It was originally square.<p>John Gage (who was on Richard Nixon&#x27;s enemy list) is the good troublemaker who thought of turning it 45 degrees like a diamond. He was Sun&#x27;s Science Officer.<p><a href="https:&#x2F;&#x2F;www.famouslogos.org&#x2F;logos&#x2F;sun-microsystems-logo" rel="nofollow">https:&#x2F;&#x2F;www.famouslogos.org&#x2F;logos&#x2F;sun-microsystems-logo</a><p><a href="https:&#x2F;&#x2F;www.enemieslist.info&#x2F;list2.php" rel="nofollow">https:&#x2F;&#x2F;www.enemieslist.info&#x2F;list2.php</a>
评论 #36247636 未加载
评论 #36247650 未加载
kazinator将近 2 年前
&gt; <i>Because we rely on recursive function calls, it is possible that your parser may run out of space on the call stack for deeply nested expressions, like 1^1^1^1.... You could mitigate this by keeping track of the depth of the expression while parsing and throwing a custom “This expression is nested too deeply” error. Another strategy is to move the parsing stack into the heap, either by managing the parser state yourself or using something like trampolining.</i><p>That would be Dijkstra&#x27;s &quot;shunting yard&quot; algorithm.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shunting_yard_algorithm" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shunting_yard_algorithm</a><p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;13637731&#x2F;1250772" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;13637731&#x2F;1250772</a><p>Shunting Yard in TXR Lisp [2015]<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;34377302&#x2F;1250772" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;34377302&#x2F;1250772</a>
评论 #36249254 未加载
IshKebab将近 2 年前
I recently had to write an expression parser. It turns out there are a few &quot;different&quot; algorithms that are common, but they&#x27;re actually basically the same algorithm: Pratt parsers, precedence climbing, and the shunting yard algorithm (there may be others, I only started looking into this a week ago). They have small differences but the basic idea is the same.<p>I went with the shunting yard algorithm because it&#x27;s not recursive so you don&#x27;t need to worry about stack overflows. It&#x27;s basically the iterative version of the other two.<p>Also note that most implementations of the shunting yard algorithm don&#x27;t actually check that the expression is valid (e.g. they accept &quot;1 2 +&quot;) but it&#x27;s trivial to fix that with a state machine to check which tokens are acceptable.<p>This was also the first thing I&#x27;ve tried writing using Copilot and it was a huge time saver. Conservatively I&#x27;d say it halved the time it took me to write it. Ok admittedly it&#x27;s probably a best case - there are a gazillion parser examples out there for it to learn from, but it was still great. I&#x27;m going to pay for a subscription.
评论 #36256068 未加载