This project has moved and is read-only. For the latest updates, please go here.

Use identifier as a function parameter

Aug 25, 2014 at 9:47 PM
Edited Aug 25, 2014 at 9:52 PM
Hi all.

The question is simple. I can easily use variables (a.k.a Identifiers) and do whatever I want with them - incrementing, assigning, etc. But what I have not yet figured out is how to use identifier with assigned value in functions (FunctionNode nodes). Let me show what I mean:

This fragment is being parsed properly:
x = 1
y = Min(3, 1)
and return value is 1 (I use custom FunctionNode to provide an implementation for Min function). What I tried to do is:
x = 1
y = Min(3, x)
This either throws exception or returns 3. Node value for 3 is {expr: 3} and for x is {expr: }
I tried to modify given example in ExpressionEvaluatorGrammar file but failed.

Is there a right way to do this? Maybe I can somehow get the list of adentifiers? Or it is not possible within current code state?

P.S. Tiny offtop question: "Shifting to S65" - is this some sort of state machine for working with Identifiers and their states? Some insights?

Aug 25, 2014 at 9:52 PM
I don't understand. Just ran your code in SampleExpressionEvaluator and it works correctly. Changed 'x=6', and it returns 3 now.
Aug 25, 2014 at 10:08 PM
Edited Aug 26, 2014 at 3:40 AM
Thanks for the fast reply.

I believe the problem is in my misunderstanding of how I should use FunctionCallNode node type. I started playing with ExpressionEvaluatorGrammar class (by coping it into my own) and tried to evaluate Min(3, 1) function (provide a simple string containing "Min" function). After I got exception "Unknown symbol 'Min'.", I decided to implement my own FunctionCallNode class and provide a function implementation in there. I made it much simplier - just parse arguments and get the node name (a.k.a. Function Name).

I tried SampleExpressionEvaluator and it worked. Am I missing smth? Where is Min (and any other standard function) being imlemented?

Update: Got it. It works through ClrInterup and default Math module. Obviously... But it doesn't work if I ran the same implementation from custom code. I believe the matter is in some inner state that lost while not running in native environment...

Update 2: Never mind, I figured all out.