JavaCC jjtTree options
来源:互联网 发布:centos查看文件夹大小 编辑:程序博客网 时间:2024/06/05 03:53
Description of jjtTree command options
BUILD_NODE_FILES (default: true)
Generate sample class implementation files for SimpleNode and any other nodes used in the grammar.
Otherwise no node class will be generated, even SimpleNode, this will depend on user to provide all node class files.
MULTI (default: false)
Generate a multi-mode parse tree.
The default for this is false, so it will generate only one type of Node, i.e, SimpleNode, and it depends on node id to distinguish them.
Look at the generated codes:
- ASTYourNode jjtn000 = new ASTYourNode(JJTYOURNODEID);
+ SimpleNode jjtn000 = new SimpleNode(JJTYOURNODEID);
And if NODE_CLASS is set, it will generate only NODE_CLASS type of Node, instead of SimpleNode, see:
- ASTYourNode jjtn000 = new ASTYourNode(JJTYOURNODEID);
+ SQLNode jjtn000 = new SQLNode(JJTYOURNODEID);
NODE_DEFAULT_VOID (default: false)
Instead of making each non-decorated production an indefinite node, make it void instead.
When set to true, it will not create a default node in the syntax tree for a NT, except an explicit declaration; and it depend on user to identify a Node in grammar.
NODE_CLASS (default: "")
If set defines the name of a user-supplied class that will extend SimpleNode. Any tree nodes created will then be subclasses of NODE_CLASS.
NODE_CLASS is the sub-class of SimpleNode.
NODE_FACTORY (default: "")
Specify a class containing a factory method with following signature to construct nodes:
public static Node jjtCreate(int id)
It will cause Node is created using ${NODE_FACTORY}.jjtCreate(…) instead of new SimpleNode, see
- SimpleNode jjtn000 = new SimpleNode(JJTYOURNODEID);
+ SimpleNode jjtn000 = (SimpleNode)${NODE_FACTORY}.jjtCreate(JJTYOURNODEID);
And the factory functions will be added automatically into SimpleNode.java
+ public static Node jjtCreate(int id) {
+ return new SimpleNode(id);
+ }
+
+ public static Node jjtCreate(ExprLang p, int id) {
+ return new SimpleNode(p, id);
+ }
+
NODE_PACKAGE (default: "")
The package to generate the node classes into. The default for this is the parser package.
It will cause all Node class generated in ${NODE_PACKAGE} package.
For example:
NODE_PACKAGE="com.yourcompany.product.model";
NODE_EXTENDS (default: "") Deprecated
The superclass for the SimpleNode class. By providing a custom superclass you may be able to avoid the need to edit the generated SimpleNode.java.
It’s super-class of SimpleNode, for example
NODE_CLASS is inherited from SimpleNode, which is inherited fromNODE_EXTENDS.
NODE_PREFIX (default: "AST")
The prefix used to construct node class names from node identifiers in multi mode. The default for this is AST.
All Nodes have prefix as ${NODE_PREFIX}
NODE_SCOPE_HOOK (default: false)
Insert calls to user-defined parser methods on entry and exit of every node scope. See Node Scope Hooks above.
It will cause following 2 functions will be called when a node scope is entry or exit:
void jjtreeOpenNodeScope(Node n);
void jjtreeCloseNodeScope(Node n);
These two functions are usually defined in main PARSER class in jjt file, for example:
void jjtreeOpenNodeScope(Node n)
{
((SimpleNode)n).setFirstToken ( getToken(1));
}
void jjtreeCloseNodeScope(Node n)
{
((SimpleNode)n).setLastToken( getToken(0));
}
NODE_USES_PARSER (default: false)
JJTree will use an alternate form of the node construction routines where it passes the parser object in.
So the PARSER object is passed to Node when it's created in PARSER.java file; the PARSER will be saved as Node’s attribute; for example:
- ASTYourNode jjtn000 = new ASTidentifier(JJTYOURNODEID);
+ ASTYourNode jjtn000 = new ASTidentifier(this, JJTYOURNODEID);
Pointer this point to the PARSER.
TRACK_TOKENS (default: false)
Insert jjtGetFirstToken(), jjtSetFirstToken(), getLastToken(), and jjtSetLastToken() methods in SimpleNode. The FirstToken is automatically set up on entry to a node scope; the LastToken is automatically set up on exit from a node scope.
So you can get the first, and next, next, ..., and the last Token of a give Node.
STATIC (default: true)
Generate code for a static parser. The default for this is true. This must be used consistently with the equivalent JavaCC options. The value of this option is emitted in the JavaCC source.
This is not used in jjtTree; it's for javaCC.
VISITOR (default: false)
Insert a jjtAccept() method in the node classes, and generate a visitor implementation with an entry for every node type used in the grammar.
It will cause a jjtAccept() function be added into each Node class; and a default Visitor interface and DefaultVisitor be created.
So that users can define their own Visitor to traverse all Nodes.
VISITOR_DATA_TYPE (default: "Object")
If this option is set, it is used in the signature of the generated jjtAccept() methods and the visit() methods as the type of the data argument.
- public Object childrenAccept(YourVisitor visitor, Object data)
+ public Object childrenAccept(YourVisitor visitor, ${VISITOR_DATA_TYPE} data)
But the VISITOR_DATA_TYPE class should be define in same package as PARSER, otherwise class's full name is required, for example
public Object childrenAccept(YourVisitor visitor, java.util.List data)
VISITOR_RETURN_TYPE (default: "Object")
If this option is set, it is used in the signature of the generated jjtAccept() methods and the visit() methods as the return type of the method.
- public Object jjtAccept(YourVisitor visitor, Object data) {
+ public ${VISITOR_RETURN_TYPE} jjtAccept(YourVisitor visitor, Object data) {
VISITOR_RETURN_TYPE class is also required in same package as PARSER, likeVISITOR_DATA_TYPE option.
VISITOR_EXCEPTION (default: "")
If this option is set, it is used in the signature of the generated jjtAccept() methods and the visit() methods.
- public Object jjtAccept(YourVisitor visitor, Object data);
+ public Object jjtAccept(YourVisitor visitor, Object data) throws ${VISITOR_EXCEPTION };
JJTREE_OUTPUT_DIRECTORY (default: use value of OUTPUT_DIRECTORY)
By default, JJTree generates its output in the directory specified in the global OUTPUT_DIRECTORY setting.
Explicitly setting this option allows the user to separate the parser from the tree files.
- JavaCC jjtTree options
- JavaCC jjtTree node scope action
- JavaCC options
- javaCC
- javacc
- javaCC
- JavaCC
- JavaCC
- javacc ()? ()* ()+
- JavaCC
- options
- Options
- options
- OPTIONS
- options
- options
- javacc-3.2
- javacc-3.2
- 关于静态和非静态
- 11.13
- JavaCC LOOKAHEAD option
- C语言 新手学习
- VS2013转换VC6.0项目失败解决办法
- JavaCC jjtTree options
- 微服务构建与部署 - Spring Boot实践
- final的使用
- 多线程
- 指针和引用的区别
- Allergo焊盘的制作 相关知识(1)
- 11.14
- 批量替换文件内容的方法
- 焦点图片轮播代码