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.



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 手机游戏下不了怎么办 硬件系统不兼容怎么办 系统主板不兼容怎么办 安装软件不兼容怎么办 win10驱动不尖锐怎么办 苹果内存太小怎么办 内存太小怎么办手机 苹果手机屏幕不能滑动怎么办 vivo手机软件不兼容怎么办 微信无法录音怎么办 手机卡住了怎么办vivo 好钱包闪退怎么办 闲鱼认证失败怎么办 闲鱼买了假门票怎么办 买黄金买到假的怎么办 闲鱼被买家骗了怎么办 闲鱼上小视频没法保存怎么办 qq空间无法查看怎么办 华为手机电池不耐用怎么办 内内被动过怎么办 hp电脑开机黑屏怎么办 网上开店快递费怎么办 保温杯外壳掉漆怎么办 拖鞋前面磨脚怎么办 塑料拖鞋磨脚怎么办 路由器进不去设置界面怎么办 手机号丢了微信登不上怎么办 电脑总是闪黑屏怎么办 支付宝破产钱怎么办 淘宝号码注册过怎么办 农行k宝怎么办信用卡 电脑页面无法显示怎么办 对方银行停止收款怎么办 淘宝东西买太多怎么办 淘宝号黑号了怎么办… 中通包裹异常怎么办 包裹退回去了怎么办 qq支付密码错误怎么办 ie8出现闪退怎么办 平板输不了密码怎么办 华硕笔记本键盘打不开怎么办