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

Re: Custom Parser

>     private class AstFix extends AnalysisAdapter
>     {
>         public void caseAParsedModel(AParsedModel thisNode)
>         {
>            node = null; // node (from Parser) must be public !
>            // this does not work

I have not read the latest version of the Java specification, but this
behavior of the Java compiler surprises me. I understand what's happening
from the VM's perspective: class AstFix is in a different runtime package
than class Parser, and it is not a subclass of Parser, so the current JVM
specification says that direct access to "node" is prohibited.  The Java
designers probably chose the current behavior to avoid having to add
proper support for inner-classes into the JVM spec.

As a fix to this, you can simply provide accessors on your CustomParser
class, something like:

class CustomParser ...
  Node getNode() { return node; }
  void setNode(Node node) { this.node = node; }

Yes it would be simple to make "node" public, but I think that this would
send the wrong message about this variable.

> Is there any other way to use an Adapter/Switch class in a custom parser?
> I'd rather not do all the code in filter (although I guess it is not such
> a big deal).

filter() + AnalysisAdapter is a good choice.

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/