The Language of Trees A Tree is defined by the following (recursive) grammar. Tree ::= '(' String Tree+ ')' | String where '(' and ')' are literals, and Tree+ means "one or more" sub-trees. Examples ======== "(hello (cat dog) (apple pear orange))" hello / \ / \ cat apple | / \ | / \ dog pear orange "goodbye" "(a b c d e f)" a / /|\ \ / / | \ \ b c d e f "(a)" // wrong "a" // correct "(a (b) (c))" // wrong "(a b c)" // correct a / \ / \ b c "3 + 4 * 5" // infix notation + Expression Tree "(+ 3 (* 4 5))" // prefix notation / \ / \ 3 * / \ / \ 4 5 "(3 + 4) * 5" // infix notation * Expression Tree "(* (+ 3 4) 5)" // prefix notation / \ / \ + 5 / \ / \ 3 4 "if (x == y) print(x) else print(y)" // code if Abstract Syntax Tree "(if (== x y) (print x) (print y))" / | \ Lisp, Clojure, Scheme, Racket syntax / | \ / | \ / | \ == print print / \ \ \ / \ \ \ x y x y