Working with expressions

Julia represents the source code of any runnable program as a tree structure. This is called an abstract syntax tree (AST). It is referred to as abstract as the tree only captures the structure of the code rather than the real syntax. 

For example, the expression x + y can be represented with a tree where the parent node identifies itself as a function call and the child nodes include the operator function + and the x and y arguments. The following is an implementation of this:

The slightly more complex expression x + 2y + 1 would look like the following diagram. While it was written with two addition operators, the expression is parsed into a single function call to the + function, for which it takes three arguments—x, 2y, and 1. Because 2y is itself an expression, it can be seen as a subtree of the main abstract syntax tree:

The Julia compiler must first parse source code into an abstract syntax tree, and then it can perform additional transformations and analysis, such as expanding macros, type checking, type inference, and eventually translating the code into machine code. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.163.58