meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tree_building [2020/02/12 10:41] – revusky | tree_building [2020/04/25 18:15] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | < | + | ====== Tree Building Enhancements in JavaCC 21 ====== |
- | ## Tree Building | + | In JavaCC 21, there is no separate program analogous to legacy JavaCC' |
- | In JavaCC21, there is no separate program analogous to legacy JavaCC' | + | |
+ | | ||
+ | * SPECIAL_TOKENS_ARE_NODES | ||
+ | * SMART_NODE_CREATION | ||
+ | * FREEMARKER_NODES | ||
- | * TREE_BUILDING_DEFAULT | + | ===== TREE_BUILDING_DEFAULT |
- | * TOKENS_ARE_NODES | + | |
- | * SPECIAL_TOKENS_ARE_NODES | + | |
- | * SMART_NODE_CREATION | + | |
- | * FREEMARKER_NODES | + | |
- | ## TREE_BUILDING_DEFAULT | + | A parser built by JavaCC 21 builds a tree by default. in other words, the setting **TREE_BUILDING_DEFAULT** is set to '' |
- | TREE_BUILDING_DEFAULT means that your parser will build a tree by default. If this option is set to false, it means that your code needs to explicitly turn on tree-building. Note the difference between disabling tree building altogether via `TREE_BUILDING_ENABLED=false` and setting this option to false. If you set TREE_BUILDING_ENABLED to false, no tree building code is inserted in your parser. If you set TREE_BUILDING_DEFAULT to false, the tree building code is present, but must be toggled on. Like so: | + | < |
- | + | ||
- | <pre> | + | |
| | ||
| | ||
- | </ | + | </ |
- | + | ||
- | Of course, in the opposite case, where TREE_BUILDING_DEFAULT is on and you want to parse input without building a tree, in the above snippet, you would have parser.setBuildTree(false). Note that this is the situation if you do not specify the TREE_BUILDING_DEFAULT option as tree building is on by default. | + | |
- | ## TOKENS_ARE_NODES | + | Of course, in the opposite case, where **TREE_BUILDING_DEFAULT** is on and you want to parse input without building a tree, in the above snippet, you would have '' |
- | This option indicates that Tokens should be treated as (terminal) nodes in the abstract syntax tree. Note that, for this reason, The Token.java generated by JavaCC21 contains extra methods that allow it to implement the Node interface. Note that TOKENS_ARE_NODES is the default. If you want the older JJTree behavior, you must explicitly set TOKENS_ARE_NODES=false in your options block. | + | ===== TOKENS_ARE_NODES ===== |
- | ## SPECIAL_TOKENS_ARE_NODES | + | This option indicates that Tokens should be treated as (terminal) nodes in the abstract syntax tree. Note that, for this reason, The '' |
- | If you set this option along with TOKENS_ARE_NODES, | + | ===== SPECIAL_TOKENS_ARE_NODES ===== |
- | ## SMART_NODE_CREATION | + | If you set this option along with **TOKENS_ARE_NODES**, |
- | This option indicates that, by default, a production should result in a new node being created if there is more than one node on the stack. This is the default behavior, since it seems to be what most people would want out of the box, and, if you want the older default, of having every production be a definite node, you must explicitly turn it off via SMART_NODE_CREATION=false in your options block. | + | ===== SMART_NODE_CREATION ===== |
- | ## FREEMARKER_NODES | + | This option indicates that, by default, a production should result in a new node being created if there is more than one node on the stack. This is the default behavior, since it seems to be what most people would want out of the box, and, if you want the older default, of having every production be a definite node, you must explicitly turn it off via '' |
- | This option means that extra code is added so that your Node objects implement core FreeMarker API's, in particular freemarker.template.TemplateScalarModel` and `freemarker.template.TemplateNodeModel`. This means that if you expose the tree you build to a FreeMarker template, you can walk the tree using a very natural syntax. Note, however, that using the FREEMARKER_NODES | + | ===== FREEMARKER_NODES |
- | </ | + | This option means that extra code is added so that your Node objects implement core FreeMarker API's, in particular '' |
===== Enhancements related to Tokens in the AST ===== | ===== Enhancements related to Tokens in the AST ===== |