[antlr-interest] Runtime code question - v3 ea4
Terence Parr
parrt at cs.usfca.edu
Mon Jul 11 11:45:28 PDT 2005
On Jul 11, 2005, at 11:18 AM, Gary Evans wrote:
> Folks,
>
> I have been studying the code in the runtime in order to translate
> it to another language,
Hi Gary! Nice to have you here. Thanks for the questions.
First thing: within a few weeks I hope to refactor the Java.stg
template file to be much smaller and easier to maintain, which would
necessitate a change to your templates (well, if you wanted to say
"similar").
> and I have a question about a couple of the classes:
> ANTLRFileStream and ANTLRStringStream. Just a quick note - I am
> not a real programmer, and I am just now learning about java, so I
> may have completely missed the boat here (so please be kind if
> this is the case).
Yeah, I wanted to revisit those class names and functionality at some
point, so please critique away!
> Within these classes is a method called "public int mark()". It
> looks like a useless method since all it does is create a
> CharStreamState object, give it the data from .p, .line,
> and .charPositionInLine, and then it just returns 0!
Excellent observation. It turns out that there can only be one mark
"location" in the current implementation; hence the marker number is
always 0. Later, when I add in syntactic predicates, we will need to
make this more general. For now, I opted for a more efficient
implementation.
> Shouldn't it do something more, like save that state back into the
> variable markers?
It saves it into a variable (an array of size 1) and then reuses it
in rewrite(m) where m is always 0.
> If not, then what method does save data into markers? All I can
> see is that when the object is initialized, it saves a blank
> CharStreamState into markers. After that, I don't see anything
> that puts more information into markers, so what is its purpose?
>
> Also, rewind() gives us the ability to go to a particular mark
> within markers and set the local variables to those values - but I
> cannot figure out where we ever set any information in markers.
The marker is set in mark() and the instance variables are wacked and
reset to the marker in rewind() :)
> FYI - I am looking at the code for antlr v3 ea4 (I think). I
> clicked on a link to download version ea5, but the name of the
> file that was actually downloaded was ea4.
That's pretty odd...sounds like a browser issue. What does
Tool.VERSION reveal?
Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
More information about the antlr-interest
mailing list