This article needs additional citations for verification .(March 2023) |
Programming languages are typically created by designing a form of representation of a computer program, and writing an implementation for the developed concept, [1] usually an interpreter or compiler. Interpreters are designed to read programs, usually in some variation of a text format, and perform actions based on what it reads, whereas compilers convert code to a lower level form, such as object code. [2]
In programming language design, there are a wide variety of factors to consider. Some factors may be mutually exclusive (e.g. security versus speed). It may be necessary to consider whether a programming language will perform better interpreted, or compiled, if a language should be dynamically or statically typed, if inheritance will be in, and the general syntax of the language. [3] Many factors involved with the design of a language can be decided on by the goals behind the language. It's important to consider the target audience of a language, its unique features and its purpose. [4] It is good practice to look at what existing languages lack, or make difficult, to make sure a language serves a purpose. [4]
Various experts have suggested useful design principles:
Many programming languages have design features intended to make it easier to implement at least the first initial version of the compiler or interpreter. For example, Pascal, Forth, and many assembly languages are specifically designed to support one-pass compilation.
Often new programming languages are designed to fix (perceived) problems with earlier programming languages, typically by adding features that (while they may make the interpreter or compiler more complicated) make programs written in those languages simpler. For example, languages with built-in automatic memory management and garbage collection; languages with built-in associative arrays; etc.
On the other hand, a few programming languages were specifically designed to make it relatively easy to write a self-hosting compiler, typically by deliberately leaving out features that make compilation difficult, such as BCPL, Pascal, and RPython.
Both interpreters and compilers usually implement some sort of symbol table.
An interpreter is a program that reads another program, typically as text, [4] as seen in languages like Python. [2] Interpreters read code, and produce the result directly. [8] Interpreters typically read code line by line, and parse it to convert and execute the code as operations and actions. [9]
Compilers are programs that read programs, also usually as some form of text, and converts the code into lower level machine code or operations. [4] Compiled formats generated by compilers store the lower level actions as a file. [2] Compiled languages converted to machine code, tend to be a lot faster, as lower level operations are easier to run, and outcomes can be predicted and compiled ahead of time. [9]
Processes of making a programming language may differ from developer to developer; however, here is a general process of how one might create a programming language, which includes common concepts:
Getting started presents the chicken-and-egg problem familiar from compiler construction: one needs a compiler to bootstrap a compiler, and bootstrapping compiler generators is no exception.