Looking Into a New Language

I have been doing some research on creating my own language as a learning experience.

2023-08-20

Written by: Kevin Sullivan

Person on Laptop

astro

blogging

netlify

language

programming

compiler

interpreter

Introduction

This blog was going to just be a thought until it really started to take shape. This is just a bit of research I have done as preperation for designing my own language. The language is going to be super simple, and just a learning experience really. It’s also probably far from being worked on. It’s probably far from planning as well since I’m still trying to crush this master’s degree. Anyway, so below is just some jumbled thoughts about what an interpreter is, what a compiler is, a virtual machine, and a Just-In-Time compiler. I thought it was all quite interesting.

Some Research

A stackoverflow post about the difference between interpreters, compilers, and virtual machines, and another post about how compilers and interpreters work.

A compiler translates the high-level code to low-level code. The translation can then be stored in some fashion, like as an executable file on your machine.

An interpreter also translates code to run on the machine, but doesn’t produce a file / store the results. It executes the statements from the high-level language as it reads them.

Additionally…

An Assembler translates assembly language code to machine code x86axx86x86ax \to x86.

Now, the virtual machine can be thought of as a software runtime. In the context of developing programming languages, it is like an interpreter for compiled code. The definition of a compiler to translate to a low-level language, instead of machine code, was intentional. A compiler can translate to a form of bytecode, which lives just above machine code, and the VM then processes the bytecode. The advantages are quicker compile and optimization times that pure compiled languages, and quicker run times that pure interpreted languages.

What does the VM actually do? Does it interpret the code, executing byte code line by line, or compile it, creating executable machine code to run? That, is up to you… which leads into the just-in-time compiler.

Finally, a Just-in-time compiler will compile code during execution rather than before execution. This can be a source code translation, but is more commonly bytecode translation to machine code, which is then executed directly. Remember, the compiler produces bytecode. It tries to compile and store frequently used code for faster execution speed. This is meant to be faster than an interpreter, which continues to just interpret code line by line.

If the idea of the JIT compiler is still fuzzy, freeCodeCamp has an article about JIT compilation. Interesting examples are Java, C#, and Pascal (the oldest I think).

Conclusion

Super short blog, it was just too big to be in the thoughts section. Hopefully I can build on this when I have more time. I think what I have read about building a language is having to build a parser to tokenize written code. The tokens are used in an interpreter or compiler to then execute. Building a high level, 4th generation, language with a very specific purpose, like SQL, might be the easiest route, and most useful for myself. More to come in the future.

Sources:
    - Image:
        title: One person typing on laptop at night generated by AI
        by: Vecstock
        url: https://www.freepik.com/free-ai-image/one-person-typing-laptop-night-generated-by-ai_41667681.htm#query=computer&position=44&from_view=search&track=country_rows_v2
        date_acquired: 2023-08-20