Search code examples
programming-languages

Programming Language Implementation


In my lecture notes "Language Implementation System" is explained as,

A language implementation system provides an interface fro programs in higher level languages to machine instructions.

And after a search Wikipedia gave me,

A programming language implementation is a system for executing computer programs.

But I am having a hard time understanding this concept. Is it talking about something like a JVM (Java Virtual Machine)?

Can someone explain this to me in simpler terms?


Solution

  • I'll give it a shot.

    Programming Language Implementation describes the method for how your code (such as Java) as an example is converted to a language that the machine (processor etc) understand. We refer to this as machine code.

    There are 2 main forms of this, compilation and interpretation.

    Technically, as the Wikipedia page points out, a compilation is converting one programming language to another (usually a lower level one). Traditionally, this refers to combining multiple input files into a single file that is runnable on the target system.

    In an interpreted language, the program is converted piece by piece while it's running on your machine.

    You mention the Java Virtual Machine, so I'm going to use that as an example. In the JVM, the Java code is compiled into Java bytecode using javac. This bytecode is then interpreted by the Java Virtual Machine and run on the underlying hardware. This is what the java command does. While Java could be described as a compiled and interpreted language, it's probably easier to think of Java itself as a compiled language, and Java bytecode as an interpreted language.

    In contrast, other languages such as C and C++ are usually converted (compiled) directly to the machine code of the target hardware platform.

    In addition to these, as @kostix pointed out in the comments, there exists transpiling, or source-to-source compiling. Transpiling refers to converting one higher level language into another higher level one. A common example is converting JavaScript ES6 to JavaScript ES5 for backwards compatibility, or C++ into JavaScript