specifying a node factory implementation

View: New views
3 Messages — Rating Filter:   Alert me  

specifying a node factory implementation

by Mauricio Pazos :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi list, I would like to use the NODE_FACTORY to produce an custom Node
implementation (and avoid the SimpleNode).
I set the following relevant option:

   BUILD_NODE_FILES=false;  // to avoid the Simple nodo generation  
   NODE_FACTORY="org.myproy.util.MyNodeFactory";

but the generated parser still use

        SimpleNode jjtn001 = new SimpleNode(...);

How can I instruct javacc to generate

        SimpleNode jjtn001 = org.myproy.util.MyNodeFactory.jjtCreate(int id);

cheers
--
Mauricio Pazos
www.axios.es


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: specifying a node factory implementation

by Tom Copeland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On May 20, 2009, at 7:04 AM, Mauricio Pazos wrote:

> Hi list, I would like to use the NODE_FACTORY to produce an custom  
> Node
> implementation (and avoid the SimpleNode).
> I set the following relevant option:
>
>   BUILD_NODE_FILES=false;  // to avoid the Simple nodo generation  
>   NODE_FACTORY="org.myproy.util.MyNodeFactory";
>
> but the generated parser still use
>
> SimpleNode jjtn001 = new SimpleNode(...);
>
> How can I instruct javacc to generate
>
> SimpleNode jjtn001 = org.myproy.util.MyNodeFactory.jjtCreate(int id);

Hi Mauricio -

Hm, when I run this with JavaCC 4.2 it seems to be using the specified  
NODE_FACTORY class, e.g.:

============
$ cat foo.jjt
options {
   BUILD_NODE_FILES=false;
   NODE_FACTORY="org.myproy.util.MyNodeFactory";
}
PARSER_BEGIN(Foo)
public class Foo {}
PARSER_END(Foo)
TOKEN : {
   <HI : "hello">
}
void Hi() : {} {
   <HI>
}

$ /usr/local/javacc-4.2/bin/jjtree foo.jjt && /usr/local/javacc-4.2/
bin/javacc foo.jj
Java Compiler Compiler Version 4.2 (Tree Builder)
(type "jjtree" with no arguments for help)
Reading from file foo.jjt . . .
File "Node.java" does not exist.  Will create one.
File "FooTreeConstants.java" does not exist.  Will create one.
File "JJTFooState.java" does not exist.  Will create one.
Annotated grammar generated successfully in ./foo.jj
Java Compiler Compiler Version 4.2 (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file foo.jj . . .
File "TokenMgrError.java" does not exist.  Will create one.
File "ParseException.java" does not exist.  Will create one.
File "Token.java" does not exist.  Will create one.
File "SimpleCharStream.java" does not exist.  Will create one.
Parser generated successfully.
$ grep myproy *.java
Foo.java:  SimpleNode jjtn000 =  
(SimpleNode)org.myproy.util.MyNodeFactory.jjtCreate(JJTHI);
Node.java:/*  
JavaCCOptions:MULTI
=
false
,NODE_USES_PARSER
=
false
,VISITOR
=
false
,TRACK_TOKENS
=
false
,NODE_PREFIX
=
AST
,NODE_EXTENDS
=
,NODE_FACTORY
=org.myproy.util.MyNodeFactory,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
==============

Note the next to last line in the output there... that's the factory  
invocation.  What version of JavaCC are you using?   Or does this code  
not represent your situation?

Yours,

Tom
http://generatingparserswithjavacc.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: specifying a node factory implementation

by Mauricio Pazos :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 01 June 2009 22:01:01 Tom Copeland wrote:
> Note the next to last line in the output there... that's the factory  
> invocation.  What version of JavaCC are you using?
Java Compiler Compiler Version 4.0
> Or does this code  
> not represent your situation?
It is right
>
> Yours,
>
> Tom
So, we need update javacc in order to use this feature.

thanks a lot.
--
Mauricio Pazos
www.axios.es

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...