How do programming languages bind identifiers to functions
Posted
by sub
on Stack Overflow
See other posts from Stack Overflow
or by sub
Published on 2010-03-30T18:50:27Z
Indexed on
2010/03/30
18:53 UTC
Read the original article
Hit count: 320
c++
|interpreter
I'm talking about C and/or C++ here as this are the only languages I know used for interpreters where the following could be a problem:
If we have an interpreted language X how can a library written for it add functions to the language which can then be called from within programs written in the language?
PHP example:
substr( $str, 5, 10 );
- How is the function substr added to the "function pool" of PHP so it can be called from within scripts?
It is easy for PHP storing all registered function names in an array and searching through it as a function is called in a script. However, as there obviously is no eval in C(++), how can the function then be called? I assume PHP doesn't have 100MB of code like:
if( identifier == "substr" )
{
return PHP_SUBSTR(...);
} else if( ... ) {
...
}
Ha ha, that would be pretty funny. I hope you have understood my question so far.
- How do interpreters solve this problem?
- How can I solve this for my own experimental toy interpreter?
© Stack Overflow or respective owner