How to add custom expression to the Expression engine?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
G-VAR
Posts: 8
Joined: Wed Dec 28, 2016 8:23 am

How to add custom expression to the Expression engine?

Postby G-VAR » Fri Mar 10, 2017 1:41 am

Hi all,

I have some custom expressions, and i want to add these expressions to the freecad expression engine.

I check the code about the expression, and see some parser files.
Just like:ExpressionParser.l,ExpressionParser.y,ExpressionParser.tab.h and ExpressionParser.tab.c
I think these files are about Bison parser,but i don't know anything about Bison.

So, what should i do?

Thanks!
eivindkvedalen
Posts: 487
Joined: Tue Jan 29, 2013 10:35 pm

Re: How to add custom expression to the Expression engine?

Postby eivindkvedalen » Fri Mar 10, 2017 7:19 am

G-VAR wrote:Hi all,

I have some custom expressions, and i want to add these expressions to the freecad expression engine.

I check the code about the expression, and see some parser files.
Just like:ExpressionParser.l,ExpressionParser.y,ExpressionParser.tab.h and ExpressionParser.tab.c
I think these files are about Bison parser,but i don't know anything about Bison.

So, what should i do?


What do you want to achieve? Do you have an example of what you want to do? If you want to add a simple function, please look at https://github.com/eivindkv/FreeCAD/tree/Fix_issue_2877 for an example.

Eivind
G-VAR
Posts: 8
Joined: Wed Dec 28, 2016 8:23 am

Re: How to add custom expression to the Expression engine?

Postby G-VAR » Mon Mar 13, 2017 5:55 am

eivindkvedalen wrote:
What do you want to achieve? Do you have an example of what you want to do? If you want to add a simple function, please look at https://github.com/eivindkv/FreeCAD/tree/Fix_issue_2877 for an example.

Eivind


Thanks for your reply, Eivind!

I'm sorry that I didn't elaborate on my question.I meaned that if i have defined a function in C++,just like "FunctionABC(int a, int b, int c)", then i want to use this function in the SpreadSheet or other workbenches. What do i need to do?

I have looked at your commit about the issue #2877,i have got some inspiration.I'm very grateful to you.

And is there anything else to consider?
eivindkvedalen
Posts: 487
Joined: Tue Jan 29, 2013 10:35 pm

Re: How to add custom expression to the Expression engine?

Postby eivindkvedalen » Tue Mar 14, 2017 7:38 am

G-VAR wrote:Thanks for your reply, Eivind!


:)

G-VAR wrote:I'm sorry that I didn't elaborate on my question.I meaned that if i have defined a function in C++,just like "FunctionABC(int a, int b, int c)", then i want to use this function in the SpreadSheet or other workbenches. What do i need to do?


Within the current framework, you should look at my branch, and extend the function class with your implementation. As long as you don't need to extend the grammer, this will suffice.

G-VAR wrote:And is there anything else to consider?


I'm considering extending the expression system to be able to add these things at runtime (from C++), but before that happens, you have to customize the code in App.

Eivind
G-VAR
Posts: 8
Joined: Wed Dec 28, 2016 8:23 am

Re: How to add custom expression to the Expression engine?

Postby G-VAR » Sat Mar 18, 2017 2:46 pm

Alright, i will have a try!

Thanks, Eivind! :D