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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Visualization of the Grammars of Ruby, Java and Javascript

56 点作者 r11t超过 15 年前

9 条评论

rictic超过 15 年前
There is far less of a difference here than might appear at first blush. These graphs might be useful for getting an overview of the grammar productions for these languages, but I don't think they are very helpful for comparing them.<p>The author processed Ruby's YACC file into something that ANTLR would accept and I'm not sure that all of the relevant information made it through. For one, it looks like Ruby's operator precedence is not captured here at all. Between this, and the fact that Ruby doesn't have separate statement and expression concepts, everything that's left ends up in one large highly connected graph.<p>The Java and Javascript graphs, generated as they are from the EBNF-like ANTLR, strike me as much more true to the productions of their respective grammars. Since they were both generated in the same way, they're also more directly comparable to one another. The most eye-catching thing about these two are of probably the chains of expressions which encode the precedence rules of their operators. Java has a boatload of operators, which account for the top half of its graph. It then has two snarls at the bottom, one for statements on the left, one for declarations on the right. Most modern languages in the algol family will have statement syntax rather similar to Java's here; if you're interested in what sets Java apart syntactically you'd likely find it clustered about the bottom right corner of the graph.<p>Javascript's operators are only slightly simpler than Java's, and there are two variations, one that allows the 'in' operator, and one that does not. This creates the two chains running down the bottom-right hand side. One interesting thing to note is the lack of tight, complicated snarls in the javascript graph. Javascript's grammar is fairly simple, and ignoring the 'in' operator, quite straightforwards, so I suppose this shouldn't be too surprising.
DTrejo超过 15 年前
ANSI C and Python grammars:<p><i>Nick said ...<p>@Adam: check out <a href="http://www.flickr.com/photos/nicksieger/281055530/" rel="nofollow">http://www.flickr.com/photos/nicksieger/281055530/</a> and <a href="http://www.flickr.com/photos/nicksieger/281055485/" rel="nofollow">http://www.flickr.com/photos/nicksieger/281055485/</a>. I can’t even imagine what a Perl grammar would look like</i>
评论 #980398 未加载
评论 #980834 未加载
评论 #980249 未加载
bmcleod超过 15 年前
This seems to be an amazingly meaningless image without a lot more context and explanation. I don't see why showing it beside other languages helps at all either.<p>Maybe we could theorise about what's easier for programmers to understand. I'd suggest in that case that the more hierarchical systems are the hardest as the brain has more difficulty remembering small numbers of connections than a larger contextual web. But that's just an idea I would have looking at the images, I expect anyone who understands these well enough to draw conclusions from them would already be quite familiar with them.
Periodic超过 15 年前
Both Ruby and Javascript seem be from the camp of adding more language features and alternate syntax to make it easier for programmers to express themselves. They are happy to put in multiple ways to do something and support multiple paradigms in an effort to make things as easy as possible for as many programmers as possible.<p>When contrasted with Python, C, or other languages that have more strict syntax you may realize that there's a cost to having so many features. The interactions between all those parts of the grammar get very complicated.
SlyShy超过 15 年前
More than just a visualization of Ruby's grammar, it also has visualizations of Java and JavaScript's grammars. The difference is pretty stark, although I don't know what to make of it yet.
评论 #980095 未加载
magoghm超过 15 年前
It would be nice to have also there a visualization of Scheme.
jhancock超过 15 年前
Add Smalltalk grammar for a beautiful and stark contrast.
brtzsnr超过 15 年前
Definitely it needs other grammars. I wish to see Python as well whose grammar is advertised as very light. Also C++ (templates), and Perl (for a contrast with Python).
dschobel超过 15 年前
I'd love to see C++ plus templates visualized.