Dan
Dan

Reputation: 2876

Is an abstract-syntax-tree always a binary tree?

I have seen many examples of AST doing arithmetic operations which look like this:

   +
 /   \
1     2

above represent 1 + 2. My question is, are all ASTs binary by definition or a node could possibly have more than 2 children?

Upvotes: 1

Views: 1347

Answers (1)

John
John

Reputation: 1351

Yes, in an AST, nodes often have more than two children. For example, a block of code is typically a node with an array of child nodes, which are statements.

Upvotes: 1

Related Questions