How to Make a Programming Language?

by Carson
258 views
Programming Languages and Compilers

There are hundreds, if not thousands, of programming languages existing across the globe, according to different sources. Each of them is unique and is good at something. Many people also invest in computer science, and you want to serve them with the best language to code, right? Perhaps, the creation might be a STEM assignment from your teacher. So, how to make a programming language?

High- and Low-Level Languages

Firstly, we need to understand high- and low-level languages. The higher the level is, the more readable the program is for humans, and the less understandable it is for computers as they are farther to machine code. Programming languages developers meet every day, such as JavaScript and Python, are high-level languages. On the contrary, C is a lower-level language because it’s closer to machine code (and possibly run faster).

Programming language levels
The difference between high-, low-level languages, and machine code
Image Credit: Canva

Compiled vs. Interpreted

So, there are two ways for a CPU to run the code you’ve written. One method compiles it, which transforms the source code into machine code before the processor does anything about the file. That way, the program can be executed quickly.

Meanwhile, another method is interpreting the program, in which the “interpreter” runs the source code directly and sends the machine code to the CPU as it translates the code into a different programming language.

Lexing and Parsing

So, let’s get a bit deeper before the compiling. Go back to the source code again because even a single line of code can be very complicated. For instance, if we have a variable declaration, namely x = a + b (where a and b already have a value).

Firstly, we have to “tokenize” every single element within the code. If the code has hundreds of lines, it’s going to take an eternity doing that. Back to the variable. “x”, “a”, “b”, and “=” needs to be separated in the lexer. If the keyword is “def”, “new”, “function”, etc., or a declared object, each character won’t be split.

def function():
    if (a == b):
        return a
    else:
        return None
function() =>

"def" "function" "" "if" "a" "==" "b" "return" "a" "else" "return" "None"

That sounds hard-to-understand, right? We thought so!

So, let us make that easier by making a “tree”. In fact, computers do so, too, as parsing. The process starts with the operator and then the next one until all values appear. If you’re unsure, you can make a profile of the action first.

x = a + b =>
Profile:
MainOperator = "=" #declaration
    VarName = "x"
    VarValue = a + b =>
        MainOperator = "+" #addition
        Param1 = a
        Param2 = b
When parsing, the tokens form a “tree”

Although we might not utilize the right keywords precisely, it still gives you some insights about how that works, right?

Start Building It!

But, remember that a programming language is simply a program. There are some methods to write that from scratch, but very few people can achieve that. You have to also write a program from a language you think it’s the most compatible. Here are a few things to consider:

  1. Understand your language’s primary purpose (for science, data processing, or web development?)
  2. Choose a programming language that you’re the most familiar with or learn one if none matches the criteria.
  3. Test yourself with your computational thinking skills: It may require improvements.
  4. Choose your keywords and syntax appropriately.
  5. Create new elements and built-in functions.

……, and more. We will elaborate on that one by one.

1. Understand your language’s primary purpose

You want to include some exclusive functions or be inspired by that language to make an excellent one. Therefore, if your language is for data processing because you want it to be used for an analytics app, go for Python or similar ones. Perhaps you need it for web development, and you can choose JavaScript.

2. Choose a programming language that you’re the most familiar with

If you create a programming language, you should dig deep into your parent language’s root. So, select a language that you usually work on. If no suitable ones are there, consider learning a new one and make them your default language for coding.

3. Test yourself with your computational thinking skills

Well, you may not be thinking “like a computer” enough to write a programming language from that language. Thus, give yourself a test. You may try starting a project with only one question, and you will optimize that to return the best and fastest results. Or, you can simply decide like a computer and try to find as much as your brain’s “source code” as possible.

4. Choose your keywords and syntax appropriately

Once you’ve completed your technical terms, you’ve got to choose easy-to-understand keywords and a strict syntax. Remember that you are also a learner of that language even though the creator is you. If everyone wants to know about writing an app in that language, you have to optimize the UI properly.

Best practices of syntaxes in programming languages
Image Credit: Canva
5. Create new elements and built-in functions

Of course, you don’t want it to be a duplicate version of another language — it may be plagiarism! Moreover, you’re willing to make your language stand out in some categories, and therefore, used by the public, right? So, learning to create a language without a base is actually necessary. Do some research and try to find unique features for your field? Don’t find one? Let’s be creative! So, imagine that you’re the developer of an app written in this programming language. What problems will you encounter? That’s what to fix!

Still stuck? Let us provide you with some ideas. For example, you can integrate HTML code more efficiently by a keyword to display the results faster. Or, you can simply make a built-in function to upload files using a drag-and-drop function.

Solve Every Problem

Writing a programming language takes decades, including updates. In reality, lots of developers are still in the root and editing the code of some well-known and commonly-used languages!

When you write a language, you must solve every single problem you encountered en route. Moreover, build a website and a forum for users to report your problems — It’s vital to produce more updates as the programmers’ demands change. This includes technical issues that can stop your program from running.

Eliminating all errors in the program
Eliminate every problem in the program to get the best results
Image Credit: Canva

Publish it when You’re Ready

After you’ve confirmed that no apparent problem exists, release it to the public by building a file type, which is an entire topic. Remember to name your file extension according to your language name.

Conclusion

So, building a programming language is a tough challenge and requires many programmers, developers, and designers to make one that is well-prepared to be in use. “Don’t get discouraged. Instead, persevere” (NASAJPL Edu, 2020).4 Remember that we can call this the “ultimate STEM challenge“.

Keep in mind that this is a very brief instruction for creating a programming language. We’ve only scratched the top of the surface, although the article contains more than a thousand words. Try to experiment more and search for relevant topics on the Internet. If you’re interested, forward this post or some better guides to your friends. If you think there’s anything essential missing, please leave that in the comments below.

References and Credits

  1. Alexandra Williams. (2017, May 23). Understanding How Code is Executed | by Alexandra Williams – Medium. Retrieved December 21, 2020, from https://medium.com/@alexandrawilll/understanding-how-code-is-executed-464c95e24b0b
  2. (2020, March 28). Difference between Compiled and Interpreted Language – GeeksforGeeks. Retrieved December 21, 2020, from https://www.geeksforgeeks.org/difference-between-compiled-and-interpreted-language/
  3. William W Wold. (2017, March 30). I wrote a programming language. Here’s how you can, too.. Retrieved December 21, 2020, from https://www.freecodecamp.org/news/the-programming-language-pipeline-91d3f449c919/
  4. NASAJPL Edu. (2020, April 30). Learning Space: Make a Spacecraft Land on Target – YouTube. Retrieved December 21, 2020, from https://www.youtube.com/watch?v=fza6p9FJDaw

Image Credit: Canva

Related Posts

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.