Tags:
tag this topic
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). <span style="text-decoration: underline;">Step 1: </span>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. <span style="text-decoration: underline;">Step 2:</span> 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) <span style="text-decoration: underline;">Step 3:</span> 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 <span style="text-decoration: underline;">Step 4:</span> 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 } <span style="text-decoration: underline;">Step 5:</span> 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 <span style="color: #7a4707; font-family: 'Courier New', courier, monaco, monospace; white-space: pre;"><meta name="robots" content="noindex" /></span> -- (c) Fordham University Robotics and Computer Vision
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r2
<
r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r2 - 2015-02-10
-
PengTang
Home
Site map
Main web
Sandbox web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
E
dit
A
ttach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback