Skip to content

Files

Latest commit

1432fa5 · Jul 3, 2020

History

History
58 lines (51 loc) · 1.33 KB

File metadata and controls

58 lines (51 loc) · 1.33 KB

Abstract Syntax Tree

AST (Abstract Syntax Tree) is a tree representation of the source code constructs, e.g., statements and expressions, which consist of further details - tokens (some very details, like semi-colon, are omitted in AST).

function abs(x) {
	if (x >= 0) {
		return x;
	}
	
	return x * -1;
}

AST Representation

  • FunctionDeclaration
    • BlockStatement
      • IfStatement
        • BinaryExpression (>=)
          • Identifier (x)
          • NumberLiteral (0)
        • BlockStatement
          • ReturnStatement
            • Identifier (x)
      • ReturnStatement
        • BinaryExpression (*)
          • Identifier (x)
          • NumberLiteral (-1)

Table/Graph Representation

FunctionDeclaration
IfStatement ReturnStatement
BinaryExpression (>=) BlockStatement BinaryExpression (*)
Identifier (x) NumberLiteral (0) Return Statement Identifier (x) NumberLiteral (-1)
Identifier (x)