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

Re: Line-by-line evaluation or all at once?

Michael Kerry wrote:
> My question is mostly conceptual, I think.  I believe that I have a two
> choices on how to implement this:...

Both approaches look OK to me.  I'm not so sure that creating a new
parser is very expensive.  The parse tables are loaded once [static
initializer], not on every instantiation.

> Specific questions:
> 1. How can I perform the short-circuit operation, above?  That is, is there
> a way to (in a caseTxxx() method I presume) return from the tree.apply()
> call?  Is this a (un)reasonable thing to do?

Throw a runtime exception and catch it out of the apply() call.  Not so
ugly, if you name your exception something like ProcessingDone.


{ tree.apply();
} catch(ProcessingDone e) {}

> 2. Assuming that I cat my expressions together, I believe all of them have
> to parse before I can apply a transformation/evaluation on the tree,
> correct? 


> 3. General comments on my problem?  Am I totally off-base in using a
> compiler-compiler for a problem like this?

You're right on track.

> 4. Does anyone know of a grammar that describes boolean + comparison
> operations?

Look at the Java and SimpleC grammars.  The "expression" part of these
grammars is a good template.

> 5. (unrelated) In Etienne's Ch. 3 example, he mentions that an EOF character
> ends the stream, saying that a CTRL-Z works on Windows 95.  I tried this on
> Windows 2000 (Adv. Server) and it didn't work!  I had to read the expression
> in from a File to get it to work.  Can anyone tell me what the EOF character
> is on Win 2000?!

I don't know, I didn't buy W2K...  Anyone else knows?

Have fun!

Etienne M. Gagnon, M.Sc.                     e-mail: egagnon@j-meg.com
Author of SableCC:                             http://www.sablecc.org/
and SableVM:                                   http://www.sablevm.org/