Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpreters written in standard C or C++

Tags:

c++

c

interpreter

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

I would like to be able to simply put all the sources in one directory, compile the sources with any standard compliant C or C++ compiler and produce an executable which reads and interprets script files in the designated scripting language.

It seems like many programming languages "written in C" often incorporate many features dependent on the platform they are in, and as a result, require some configuration program to run based on your target system (e.g. Autoconf) which complicates matters and limits cross-platform compatibility.

Reason for question:

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

As this is just for educational purposes, the scripting language doesn't need to support super low level features like C, nor does it have to feature GUI like Java (I don't think you can write any kind of GUI limited to standard C/C++ anyway) or any complicated io for that matter. However, I would like the language to be complete enough that it would be practical to write some useful programs in the language (e.g. It should be possible to extend the language using C/C++ so that you can use it like a shell on tty).

Thanks.

Edit:

@AndréCaron I would prefer it if at least the core of the language was 100% platform independent. It would be ok if the language included a large standard library that depended on other libraries to make it "more useful", however, I would like to be able to strip the standard library and use just the core of the language (possibly with custom hand written libraries) if I wanted to.

like image 307
math4tots Avatar asked Jan 27 '12 23:01

math4tots


People also ask

Which interpreter is used in C?

Ch is a complete C interpreter that supports all language features and standard libraries of the ISO C90 Standard, but extends C with many high-level features such as string type and computational arrays as first-class objects. Ch standard is freeware but not open source.

What is C language in interpreting?

A 'C' language is one which the interpreter understands perfectly but into which they do not work. They will interpret from this (these) language(s) into their active languages. It is therefore a passive language for the interpreter.

Is C is a interpreted language?

What is Compiled Language? A compiled language is a programming language that is converted into machine code so that the processor can execute it. The compiled languages are usually compiled, not interpreted. For better understanding you can go through the types of compiled language – CLEO, COBOL, C, C++, C#, etc.

In what programming language is the interpreter of compiled by code written?

Java is both Compiled and Interpreted. To exploit relative advantages of compilers are interpreters some programming language like Java are both compiled and interpreted. The Java code itself is compiled into Object Code. At run time, the JVM interprets the Object code into machine code of the target computer.


2 Answers

Maybe embedded Lua?

Actually core Lua itself is probably better. At first glance, I though eLua's claim of running on many different systems meant it was highly portable, but in fact it takes core Lua and adds a bunch of hardware drivers, which obviously aren't so portable.

Ocaml would be another excellent choice. It claims "The bytecoded system currently runs on any POSIX-compliant operating system with an ANSI-compliant C compiler" And Caml Light is especially suitable for learning. "The runtime system and bytecode interpreter is written in standard C, hence Caml Light is easy to port to almost any 32 or 64 bit platform."

like image 105
Ben Voigt Avatar answered Sep 19 '22 07:09

Ben Voigt


Lua is really your best bet. The core Lua interpreter is about as minimalistic as you can get. The distro includes a makefile, but it's about as bare-bones as it gets. There are even instructions that explains which files you need to build just the core language, which ones are the Lua standard library, and which ones are the command-line interpreter.

The core language itself doesn't touch any platform-specific APIs or headers. The standard library does, but only in the most minimal way. And you don't have to build the standard library if you don't feel like it.

There are some #defines you can use to configure the build, but that's mostly for things like DLL building and the like.

Note: The purpose of autotools and other platform-specific build configuration utilities is to allow libraries to effectively wrap platform-specific stuff within a platform-neutral interface. There's not really much you can do on most platforms with pure platform-neutral C or C++ standard libraries. You can't even access directory trees and search for files, let alone really useful things like bringing up a window. For simple stdin/stdout applications, that might be enough. But for the vast majority of cases, it isn't.

My suggesting is that you get used to having to configure a build for a specific platform. Unless your domain is scientific applications (and in some cases, not even then), you're not going to get much out of platform-agnostic programming. You're going to have to learn to work with these kinds of libraries.

Lua is an outlier when it comes to libraries. Most libraries are not lists of files you can just shove into a directory and compile willy-nilly. The sooner you figure out how to work with the tools that libraries use, the better off you'll be.

like image 26
Nicol Bolas Avatar answered Sep 23 '22 07:09

Nicol Bolas