简体   繁体   中英

How looks like an Expression-Tree (when function calls are involved)

I've found many places that shows expression-trees that involve operators (+,-,*, &&, ||, etc). Here is a simple example:

在此处输入图像描述

But I can not find an example when functions (with zero or more arguments) are involved. How would following expression be represented using an Expression-Tree?

mid( "This is a string", 1*2, ceil( 4.2 ) ) == "is i"

Thanks a million in advance.

After weeks of researching, I was not able to find the "official" (academic) answer to this question. So I took my own path and I can tell it works smoothly. I'm offering it here because so far no one gave an answer: just in the case this could help someone.

By asking this question, I wanted to know if I should place the arguments passed to a function as child nodes of the 'function node' or as a property (data) of the 'function node'.

After evaluating pros and cons of both options, and as nodes in an AST tree can store as many information as you need/want/please (the 2 siblings 'left' and 'right' are just the minimum), I thought this was going to be the easiest approach; it is easy to be implemented and it works perfectly.

This was my choice: place the arguments of the function as data into the 'function node'.

But if any one has a better answer, I beg you to share it here.

It might help to think of an expression tree as already being a way of representing functions applied to a set of arguments. For example, a - node has two children, which you can think of as representing the two ordered inputs to the “minus” function.

With that in mind, you can generalize your expression tree by allowing each node to contain an arbitrary function with one child per argument to the function. For example, if you have a function max that returns the maximum of two values, the max node would have two children. If you have a function median that takes three arguments and returns the median, it would have three children.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM