

Visualization of the Grammars of Ruby, Java and Javascript - r11t
http://blog.nicksieger.com/articles/2006/10/27/visualization-of-rubys-grammar

======
rictic
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.

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.

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.

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
ANSI C and Python grammars:

 _Nick said ...

@Adam: check out <http://www.flickr.com/photos/nicksieger/281055530/> and
<http://www.flickr.com/photos/nicksieger/281055485/>. I can’t even imagine
what a Perl grammar would look like_

~~~
jazzdev
_I can’t even imagine what a Perl grammar would look like_

Since there's no BNF for Perl it would be hard to visualize its grammar.

~~~
james2vegas
perly.y might help (sadly it recently went from yacc to bison).

------
bmcleod
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.

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
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.

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
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.

~~~
r11t
I have edited the title to reflect that it also includes Java and Javascript.

------
magoghm
It would be nice to have also there a visualization of Scheme.

------
jhancock
Add Smalltalk grammar for a beautiful and stark contrast.

------
brtzsnr
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
I'd love to see C++ plus templates visualized.

