Prefix, Infix, and Postfix Operations 

Expressions can be constructed from operands and operators.

Prefix operations 

Prefix operations are written using one of PLUS(tree), MINUS(tree), NOT(tree), or TILDE(tree):

PLUS(LIT(1))                 // +(1)
MINUS(LIT(1))                // -(1)
NOT(FALSE)                   // !(false)
TILDE(LIT(1))                // ~(1)

Postfix operations 

Postfix operations are written by calling POSFIX(sym|"x") on a tree or a symbol:

LIT(1) POSTFIX(Any_toString) // 1 toString

Infix operations 

Infix operations are written using INFIX(sym|"op") as follows:

LIT(1) INFIX("+") APPLY(LIT(2))

This prints as:

1 + 2

Alternatively, INFIX(sym|"op", arg, ...) can be called with righ-hand side arguments:

LIT(1) INFIX("+", LIT(2))    // 1 + 2

For commonly used operations treehugger DSL defines some built-in operators, which will be covered later:

LIT(1) INT_+ LIT(2)          // 1 + 2

Infix chaining 

treehugger DSL provides a way to chain infix operations using INFIX_CHAIN(sym|"op", tree, ...):

INFIX_CHAIN("+", LIT(1), LIT(2), LIT(3))

INFIX_CHAIN(Any_==, LIT(1) :: LIT(2) :: LIT(3) :: Nil)

The above print as:

1 + 2 + 3

1 == 2 == 3