[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's the story with SableCC?

Hi Terence,

>Anyway, what's all the hubbub about?  Yet another parser generator
>that can build trees?  What am I missing?

You are probably missing the "readability of the code", and the "simplicity
of the system". I do not pretend that SableCC is "the" parser/AST generator.
I am just trying to convey a better software engineering approach to
multi-pass compiler construction; a cleaner separation of compilation phases
and a less error prone coding convention (with names instead of numbers).

There is no one "truth" about how a compiler must be built. I am just
suggesting one way. If you like it, use it. If you don't, just ignore the
whole thing.

>Sounds like they have some nice
>action / grammar separation stuff, but...

That's a part of what SableCC is about.

>I have only two comments:
>1.  "Compiler-compiler" is and has always been a misnomer.

Everyone knows this (I hope).

>The most accurate description for most language tools is probably parser
>compiler or parser generator with AST construction.  To say you built a
>for BASIC in 300 lines is very misleading.  What you have built is (I
presume) a
>simple BASIC (not VB) to bytecode (Java?) translator, which is a semester
>undergraduate project even when you write it by hand completely.

I said an -> interpreter <-.  And I more importantly said "readable" code:-)

>I have lots of friends that build actual compilers (source to machine code)
>the various chip folks and they all tell me that the parser and tree
>is like 10% of their problem at most.

SableCC is not about scanning/parsing. It is about object-oriented
multi-pass compiler construction. You might argue that the AST is the best
(or not) data structure. But many optimizing compiler guys, including me,
(working on intermediate representation of programs [not the back-end
peephole optimization guys]) believe that an AST is a good data structure to
work with. SableCC is there for those guys, if they want to use it.

>The most important question in translation is "What can you do with trees
>when you get them?"  After building a million tree walkers by hand,
>I built SORCERER and then incorporated the tree grammar stuff into
>ANTLR itself.   Why would anybody do depth first search callbacks
>when you can use a grammar to specify the structure of the tree and
>when/where to do actions?  Even the gang of four book says that you should
>use a mathematical description of a problem anytime you can.
>After you've written as many giant (like 9 phase) source-level translators
as I
>you'll notice that grammars are a great way to manipulate trees.

You have probably not read the documentation on the SableCC web page...
Mainly, I explain that the grammar and the AST are so much alike, that you
can directly code your actions in the visitor, the same way you would do in
a grammar. It's as readable and as intuitive.

The advantage: You will debug your written code directly, not some generated
code mixed with the action code embedded in the grammar.

Again, if you don't like the idea, no body is forcing you to use SableCC.

>In summary, your tool seems very nice (although you should have stayed away
>from LALR(1) <wink>), but tree construction is a very small part of either
>real translator or a real compiler.  In the space of parser generators that
>trees and apply actions to nodes, welcome. :)

>From your point of view, I am probably in the wrong camp (having chosen the
LALR(1) <wink>). But the point of SableCC is not about the lexer/parser/AST
generator. It is about writing readable and maintainable, multi-pass
compilers in Java.

FYI, I have worked on a multi-pass optimizing compiler for many years. It
was written in C. One of the main problems has always been those "rare"
cases where the AST got corrupted. I will let you guess how easy/hard it was
to find such bugs;-) You probably know it if you worked on optimizing
compilers that modify the intermediate representation.

Thanks for taking some of your precious time to express your opinion on


PS: Please don't waste time arguing anymore. By now, everybody has made up
his idea. Sincerely, I think that semantic predicate can be great. They just
didn't fit nicely in the SableCC framework.

PPS: To people on the javacc-list: This is definitely my last posting on
this thread (i.e. the SableCC ANNOUNCE thread). From now on, I will spend my
time improving SableCC and helping people on the sablecc-list
(http://www.sable.mcgill.ca/sablecc/). Enough unproductive time has already
been spent arguing.