[antlr-interest] Parser - > Tree walker

Jim Idle jimi at temporal-wave.com
Tue May 22 12:45:11 PDT 2007


I think you miss the point or choose to make rewrite rules more
complicated than they are, merely in order to justify your dislike of
tree grammars. 

 

The reason the programmers knows Java is because they bothered to
learned the language they are using. If you are writing a recognizer
using ANTLR, then presumably you are willing to read the manual a
little. Learning rewrite rules is trivial compared to learning about
non-determinism and how to write context free grammars, most of which
has nothing to do with the tool you are using. The knowledge required to
learn the internal structure of nodes is far less accessible.

 

 

Anyway, this has been done to death in the past.

 

Jim

 

From: Andy Tripp [mailto:antlr at jazillian.com] 
Sent: Tuesday, May 22, 2007 12:06 PM
To: Jim Idle
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Parser - > Tree walker

 

Jim Idle wrote: 

IMO, the code you have shown here is less obvious than distinguishing
the semantic case in the tree generating parser, which actually involves
less typing and less knowledge.

As for less typing, the important thing is not how many characters it
takes, but how readable it is.
And readability is a function of the amount of knowledge of the reader,
not the writer.

As for knowledge, we have to consider what the programmer presumably
already knows.
I think virtually every programmer knows how to do a switch based on a
node's type
and get a node's child count. Compare that to very few programmers who
know what
this ANTLR syntax means: 
'-' ue=unaryExpression      -> ^(UNARYNEG $ue)

IMO, probably 99% or more of all programmers could write (and easily
read)
the vanilla code that I showed, while less than 1%
(those with non-trivial ANTLR experience) could write the code you
showed.

"Ergo" is latin for "therefore". It's shorter to type, and perhaps "less
knowledge".
Whether it's easier to read and write depends on the reader/writer.
In English-speaking countries, most people already know "therefore", and
so learning
"ergo" means having to aquire extra knowledge. Same for programmers who
already
know a language like C/C++/Java and are trying to walk a tree. 

Nothing against Latin or ANTLR, just trying to keep the writers and
programmers productive :)



 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Andy Tripp
Sent: Tuesday, May 22, 2007 11:05 AM
To: CARLOS MELGAREJO
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Parser - > Tree walker

 

I'm sorry to keep doing this to the mailing list...I keep jumping in
once a month
with pretty much the same negative comment...but here goes anyway ;)

You're walking a tree-like data structure. You're at a '-' node, and you
want to distinguish
between the one with one child and the one with two children. IMO, if
you can't just
crank out the obvious code:

switch (node.getType()) {
    case MINUS:
         if (node.getChildCount() == 1)  // unary
         else    // binary
         break;
}




 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070522/d470f0f2/attachment-0001.html 


More information about the antlr-interest mailing list