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

Some questions...

Hi everybody,

I have been following this list for a few months now and I've finally gotten
around to starting a project in SableCC.  What I need to write is a Java
pre-processor that introduces new keywords into the language and outputs
standard java as its generated code.  I've looked at the included Java 1.1
grammar and this looks like a very good starting point.  I do have a few
queries though:

1)  I need to preserve as much of the original source formatting (and
comments) as possible.  My intention is to write a custom Lexer that builds
a hash to record the ignored tokens (white space, doc comments, eol comments
and normal comments) that occur before each non-ignored token.  Then when I
output the parsed tokens (in most cases the code should just pass through
the pre-processor), I can just print out the ignored tokens first to
recreate the output.  Does this sound feasible?  I thought it might be a
little slow...

2)  I think I've finally got my head around the idea of applying a modified
DepthFirstAnalysisAdapter to the AST (which I must say is a really cool
solution...).  What I'm still having a bit of problem with is storing
attributes like type information.  The way I understand it, you need to
store an association of the node in question to the attribute data in a hash
table in the Analysis class using setIn/getIn/setOut/getOut.  But why is
there these two versions; In and Out?  I must be missing something.  I get
the In/Out thing with the methods called during the tree walk, but I don't
see how this relates to attributes.  Do you store the attribute info you
generate with the in* methods with (set|get)In and the attribute info you
find in the out* methods in (set|get)Out?  This seems to make sense
somewhat, but why keep them in separate hashes?

3)  Is the included Java Parser optimised at all?  The thesis seems to imply
that it is, but I couldn't see it in the source...

4)  I'm going to have something of a problem with line numbers when I pass
the post-processed text to a compiler (it must also be human readable...)
like javac.  Is there any java equivalent to the #line directive in C?  I
think not, so I'm preparing to use another hash to map line numbers back to
the original source.  Any bright ideas?

Any help & guidance you could give me would be most appreciated,


Jim Moores
Jim Moores, Director, Quickstone Technologies Limited.