Tree t = `(+ (id x) (id y));is the same as the following code.
Tree t = new Tree(:+, new Identifier(:x), new Identifier(:y));You may cut and paste the output of tree.print() after the backqoute ("`") to embed it into the source code. (Cut and paste is preferred to prevent typing errors.)
As with the lisp backquote macro, you can also use commas (",") and comma at marks (",@"). Commas embed the evaluated result of the value of a Java expression following the comma into the tree. Comma at marks assume the evaluated result of the value of a Java expression following the Comma at mark as an array and embeds it into the tree. For example, the following
Tree t = `(+ (id x) ,val);is the same as the following code.
Tree t = new Tree(:+, new Identifier(:x), val);And the following,
Tree[] sa = { s2, s3, s4,}; Tree t = `(block ,s0 ,s1 ,@sa ,s5 ,s6);is the same as the following.
Tree t = new Tree(:block, s0, s1, s2, s3, s4, s5, s6);
The type of the expression that follows the comma must be "Tree", while the type of the expression that follows the comma at mark must be "Tree[]" or "TreeVec".
Regarding the grammar, there is one important point you must be careful of. If the expression following the comma or comma at mark is not a variable name and is a complex expression, you must surround the expression with parenthesis. For example, while the following is correct,
`(= ,var ,val)the following
`(= ,getVar() ,getVal())will not be parsed as expected. This expression must be written as follows.
`(= ,(getVar()) ,(getVal()))
Also note that the current version does not accept expression such as the following.
`(,tag ,arg1 ,arg2) `(id ,name) `(literalTree ,literalTag ,literalContents)You must use the following Java expression instead.
new Tree(tag, arg1, arg2) new Identifier(name) new LiteralTree(literalTag, literalContents)
Tree t = `(+ (* (id x) (id y)) (literalTree int "1"));will be able to be written like the following.
Tree t = CODE:E{ x * y + 1 };