Translators written in standard C or C ++ languages

Are there extensible interpretable programming languages ​​written in standard, platform-independent C or C ++?

I would just like to place all the sources in one directory, compile the sources with any standard C or C ++ compiler and create an executable file that reads and interprets script files in the specified scripting language.

It seems that many programming languages ​​written in C often include many functions depending on the platform on which they are located, and as a result, some configuration program is required to run based on your target system (for example, Autoconf), which complicated issues and limited cross-platform compatibility.

Reason for question:

I am interested in learning about programming language design. I played with some toy programming languages ​​after the following lessons involving yacc, lex and llvm. Recently, however, I have become interested in learning a programming language written in portable C / C ++, so I can study the program and code on any machine that supports the standard C or C ++ compiler (possibly even on my ipad) and still have a fairly uniform experience.

Since this is for educational purposes only, the scripting language does not need to support super low-level functions such as C, and it should not include a graphical interface similar to Java (I don’t think you can write any GUI limited to standard C / C ++ anyway) or any complex io for that matter. However, I would like the language to be complete enough to make it convenient to write some useful programs in the language (for example, it should be possible to extend the language with C / C ++ so that you can use it as a shell in tty) .

Thanks.

Edit:

@ AndréCaron I would prefer that at least the core language is 100% platform independent. It would be nice if the language included a large standard library, which depended on other libraries to make it “more useful," however, I would like to be able to split the standard library and use only the core language (possibly with a custom written manually) if I wanted to.

+6
source share
4 answers

Could it be built-in Lua ?

Actually the main Lua is probably better. At first glance, although the eLua requirement to run on many different systems meant that it was very portable, it actually uses the main Lua and adds a bunch of hardware drivers, which are obviously not so portable.

Ocaml is another great choice. He claims that “the bytecode system currently runs on any POSIX-compatible operating system with an ANSI-compatible C compiler” and Caml Light is particularly suitable for training. "The runtime system and the bytecode interpreter are written in standard C, so Caml Light can easily be ported to almost any 32-bit or 64-bit platform."

+9
source

Lua is your best bet. The main Lua interpreter is about as minimalist as you can get. The distribution includes a make file, but it’s like bare bones. There are even instructions that explain which files you need to build only for the main language, which ones are the standard Lua library, and which ones are the command line interpreter.

The main language itself does not apply to any platform-specific APIs or headers. The standard library works, but only in the most minimal way. And you do not need to create a standard library if you do not like it.

There are some #define that you can use to customize the assembly, but mostly for things like building a DLL, etc.

Note. The purpose of setting autotools and other configuration utilities for a particular platform is that libraries allow you to efficiently transfer platform-specific things within a platform-neutral interface. On most platforms with very clean, platform-independent C or C ++ libraries, there are actually not many. You can't even go to directory trees and search for files, not to mention really useful things like creating a window. For simple stdin / stdout applications this may be enough. But for the vast majority of cases this is not so.

I assume that you are used to customizing the build for a particular platform. If your domain is not a scientific application (and in some cases even not then), you are not going to get much from an agnostic programming platform. You will have to learn how to work with these libraries.

Lua is an outlier when it comes to libraries. Most libraries are not lists of files that you can simply insert into a directory and compile perforce. The sooner you figure out how to work with tools that use libraries, the better.

+6
source

LUA and TCL are the two simplest interpreted languages, so get a copy of the source code for both and consider it. However, I think your question has more to do with static linking to shared communication. A statically linked program does not have system dependencies that go beyond the kernel interface, but a dynamically linked program requests the correct set of shared libraries to be installed.

With a language like Python, you need to worry about your own Python libraries (called modules), as well as any binary shared libraries that the module depends on. Python itself is usually created using shared libraries, but it can be created statically . In addition, I created a binary of Python that uses the RUNPATH function for the shared Linux library so that all binary dependencies can be linked to Python in its own hierarchy folder.

If your question is about binding, see how StaticPython is built compared to standard dynamic Python and Pybuild scripts using RUNPATH.

0
source

Almost all the latest script languages ​​are written in C or C++ : Perl, bash, csh, PHP, html, Javascript, make, vim, tcl, etc. etc.

The fact that their creation requires configuration is not a feature of the interpreter, since it is an adaptation for building on multiple platforms - it is usually considered good.

They are all extensible in the sense that you can write functions that create new functionality.

0
source

Source: https://habr.com/ru/post/907080/


All Articles