[antlr-interest] Re: Help with Java grammar

cliftonccraig ccc at icsaward.com
Thu Mar 11 06:48:37 PST 2004


Thanx Ric,

I have tried running in my debugger but I couldn't follow all of the
jumps that were made. It appeared to be jumping back and forth between
two statements in a switch nested in a infinite while loop. I couldn't
tell at that point if it was stuck of trying to match some complex
lexer rule or what. That experience did, however, point me to the fact
that it was the last single line comment that was hanging everything
up. I think I noticed it (the single line comment) when I eval'ed a
buffer or something. I couldn't understand exactly what was happening
but I knew it had to be at that point in the processing and then when
I looked back at the input file I then noticed the comment was on the
EOF line. I recalled reading somewhere that you shouldn't end a source
file with EOF (probably an article on the ANTLR or JavaCC site) and
made an educated guess that this is what was causing my problem. I
confirmed my suspicion when I inserted a newline in the input file and
all was good. I later (at home) tried the parser out of the box on one
of the tests that ship out of the box and got the same results after
putting a single line comment on the last line. That confirmed, for
me, that it was not the additional logic from the rewrite engine that
 was causing this. (I didn't think it would be but I had to confirm
it.) I know little of why it happens and I will try to look into it
again a little later. I'm sure anyone could replicate the problem just
by downloading the Antlr package, generating the JavaReckognizer with
the included grammar and running over any Java file that ends with a
single line comment. For now I have my work around in place. I'd love
to improve on it because it always inserts a new line which is carried
over into the rewritten file. (Ooh, I just thought of a workaround for
my workaround!) I'd love to take your advice on overridding the
CharBuffer or whatever but I know little of these classes and have
only been working with this technology for a matter of days. I'm not
stupid, I'm just afraid it will take me some time to figure out what
to put where in the overriding logic. Thank you for all of your help.
I really appreciate it. You will probably here back from me on this
mailing list when I get back to working with this.

Cliff

--- In antlr-interest at yahoogroups.com, Ric Klaren <klaren at c...> wrote:
> On Tue, Mar 09, 2004 at 04:25:17PM -0000, cliftonccraig wrote:
> > Still no luck. I tried your suggestion and while it went through the
> > ANTLR generator ok it didnt stop the OutOfMemory error.
> 
> Where does the out of memory error come from (can you get backtraces of
> where it bombs out)? Did you try running the lexer standalone (e.g.
just do
> nextToken in a loop) and see if it groks the offending input file.
> 
> Are you doing stuff in the uponEOF handler (maybe in combination with
> tracing turned on)? Does it also happen with a trivial input file ?
If so
> did you try single stepping trough it with a debugger.
> 
> > It sounds like overkill but I just don't see any easier way to do
> > this. I thought I saw a way to chain or concatenate to InputStreams
> > together as one in some book or article but I can't remember. Please,
> > could someone help me with either solution. I feel so stumped.
> 
> It might be easier to use a custom InputBuffer that adds a "\r\n" before
> EOF. InputBuffer seems to me as a simpler class to override. For
java mode
> you'd probably have to look at CharBuffer.java looks like you only
have to
> add one check in the fill method. Then use the more specific
constructors
> of the lexer to glue stuff together.
> 
> Cheers,
> 
> Ric
> --
>
-----+++++*****************************************************+++++++++-------
>     ---- Ric Klaren ----- j.klaren at u... ----- +31 53 4893722  ----
>
-----+++++*****************************************************+++++++++-------
>   "Good judgement comes from experience.
>      Experience comes from bad judgement." --- Unknown



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list