[antlr-interest] philosophy about translation
Sohail Somani
sohail at taggedtype.net
Tue Oct 10 22:06:17 PDT 2006
On Tue, 2006-10-10 at 11:12 -0400, Andy Tripp wrote:
> Sohail Somani wrote:
> >>Its weird that you're walking token streams, but what it seems it that
> >>you're implementing the recursive descent parser by hand...
> >>
> >>
> But a parser converts a token stream to an AST, I'm not using an AST,
> but dealing with
> the stream directly because that seems easier to me. I find it easier to
> search for
> pattern "f(...) {" to look for a function, rather than search a tree for
> a node of type
> FUNCTION_DECLARATION.
A parser doesn't *have* to create an AST. For example, consider a syntax
directed translation. That is something that simply recognizes token
structure and performs some actions.
> >I believe there is an unspoken rule that all bets are off with COBOL?
> >
> >
> Yes, I suppose. But even with C and C++, what seems simple may not be.
> For example, you'd think that
> struct person p[100];
> might correspond to a single line of Java, but it doesn't (you need to
> initialize the
> array). So suddenly, out of nowhere, you may have to add a static block
> of code. That's
> a typical one-to-many type of thing.
I'm not sure how an AST a la antlr prevents you from doing this.
> because it may certainly have changed since you last looked at it..in
> other words, the symbol
> table can be a mess to maintain. In my case, the return type of b() may
> have change, the name of it
> may have changed, its argument types may have changed.
Changed from what to what? And how the heck can they change in a single
run of the compiler? I'm confused.
> Also, my tool does not have to be fast - if it takes an hour to
> translate some code, when it could
> have taken 2 seconds if I had designed it "right", that's ok.
I don't think anyone is telling you that you didn't design it right! I
myself would like to have the power of:
v1 = v1 + v2 => v1 += v2
transformations. Myself, I'm only trying to figure out what the big deal
is that prevents you from using antlr. Personally, I know I wouldn't
want to write token matching code.
Please don't think I am attacking your translator. We all know how
difficult the problem is you're trying to solve. All I'm trying to
understand is how you solved it.
More information about the antlr-interest
mailing list