1

all programming languages have api's to interact various systems as a example

  • javascript languge has Dom api to interact with the web page.
  • C language languge has file access api to interact with Files.


my questions is how to create such a API's From mere programming languge ?
as a example

  • how DOM APi created in javascript language
  • how File access APi created in C language
4

You do it by using the facilities the the run-time system offers and putting that code into a library.

For instance, file-handling code depends on how your system deals with files to begin with. On UNIX systems this is done through syscalls with explicitly defined parameters. So what you have to do is write C code that uses the syscalls which do what you want and make that functionality available through extrnally visible C functions. (In the case of UNIX, the OS itself will usually also have been written in C, but that is irrelevant to this question. The method would be the same for a Pascal compiler on a kernel written in C or a C compiler on a Lisp machine.)

This means that you have to repeat the process for every different platform your language implementation should run on. Making the code into a library (in the case of file manipulation, this will probably be the standard library) ensures that the high-level-language programmer doesn't have to learn about the intricacies of file handling on different systems, but need only understand the C files API.

For Javascript, the run-time environment is usually the browser, which already implements the DOM. Therefore, the Javascript interpreter has to be programmed against the existing DOM API in the browser and compiled into the browser. Again, the Javascript program need not understand different browsers, but only the API defined by the interpreter.

  • To complement this answer, you may want to look at the source code of the Python interpreter. It comes with a huge standard library, some of which is written in C (the platform specific bits), and the rest on Python itself. Try to compile a distribution from source (it's really well documented), I think it's worth your time. – Tibo Jul 21 '17 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.