Tags:
create new tag
view all tags

Adding a new n-ary operator, ie a function, to matheval

Example, lets add the 2-ary function tss_blah(a,b).

Step 1: Edit scanner.l and add

|tss_blah

to the of the constants list. The '|' is the flex operator for OR, since constants is a list of possible names and it must separate the names.

Step 2: Edit symbol_tableV.c and add

"tss_blah" to the intialized list of names functions_2V_names

tss_blah to the initialized list of functional pointers functions_2V

(If you waated new 3-ary functions, add to functions_3V_names etc)

Step 3: Put in an external declaration for the function in dlibinterface.h

extern void *tss_blah(void *arg1, void *arg2)

functions take and return data as void *, because there are many different types. They need to be cast at some point to the right type.

You can directly add a C function to xmathV.c and xmathV.h if you want a local function. This is good for functions that calculate simplile stuff.

However, if you need MOGS, c++ etc, then go to the nextstep

Step 4: Only do this if you did not do a local function in xmathV.c, add to xmathV.h as well

Make a function in dlibinterface.cpp that does the work you need done

extern "C" void *tss_blah(void *a1, void *a2) {

stuff in here

}

Step 5: Probably don't need to do this.

It is the assumption that functions return reals. If you don't return a type real, then you may need to have the type of the return figured out.

This is done in evaluate node in nodeV.c, under the 'f' switch case.

For 1-ary and 2-ary functions, real is the only currently implementd case.

For 3-ary functions, the type of the argumentsis used to decide on the type of the result.

tss_condD(takes a real, a mog and a mog and returns a mog. tss_pdiff takes a mog, a mog and a real and returns a real.

For 3-ary functions the variable argtypes_flag is used as a binary flag to remember the types of the arguments.

Files change checklist:

scanner.l, symbol_tableV.c, symbol_tableV.h, dlibinterface.h, dlibinterface.cpp, xmathV.c, xmathV.h

<meta name="robots" content="noindex" />

-- (c) Fordham University Robotics and Computer Vision

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2015-02-10 - PengTang
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback