8
$\begingroup$

Say, I wanted to create my own programming language. Assuming that I have made all of the decisions about how I want it to look and act, do I just need to write a compiler for it?

For example, is the high-level Java code anything other than just text and this text is in the correct format for the compiler to accept it and turn it into something else?

My question is, is the creation of a programming language done through a compiler? High-level is fine.

$\endgroup$
  • $\begingroup$ Is your question about making programming language definition precise? $\endgroup$ – Anton Trunov May 10 '16 at 19:49
  • $\begingroup$ Not really. It's more, could I theoretically make my only language up purely by just making a compiler which parses some text? Where this text is my made-up language in my syntax. For example, is System.out.println() Java because the Java compiler accepts that or is there some other thing working here. $\endgroup$ – Haych May 10 '16 at 20:41
  • 3
    $\begingroup$ What do you mean by "the creation of a programming language"? What do you mean by "done through"? It's hard for me to tell exactly what you are asking. You say you have already made all of the decisions about how you want the language to look and act; what more is there to the creation of a programming language, from your perspective? If you try to elaborate what you are trying to achieve it will probably be possible to give you more helpful answers about how that can be achieved. Right now it seems like we have to guess what you might be asking. $\endgroup$ – D.W. May 10 '16 at 22:12
10
$\begingroup$

The short answer is no.

You can think of a programming language as a mathematical formalism used for expressing computation. A compiler/interpreter is a just a piece of an actual software that carries out that computation, and should not serve as the language specification.

That being said, in addition to lexical and syntax specification of a language, you should also define semantic specification, i.e., what does a (syntactically correct) program written in your language actually mean. The obvious semantics to start with is operational semantics, where the meaning of a program is given in terms of how the program actually runs. That is, it (mathematically) precisely defines how programs execute. On top of this semantics you should build an actual compiler/interpreter with optimizations and so forth.

Specifying full operational semantics of your language will give you a formal language documentation and it will make you understand your language to the very details. Also, it will allow you to formally reason about some aspects of the language. Writing down operational semantics is really a good habit.

There are other useful semantics as well, such as axiomatic, denotational, and game semantics. However, they are more advanced and typically don't make their way into a compiler/interpreter.

$\endgroup$
  • 3
    $\begingroup$ This is wrong. A programming language without a formal specification is still a programming language. $\endgroup$ – reinierpost May 10 '16 at 20:31
  • 3
    $\begingroup$ @reinierpost So, your answer to the question "is the creation of a programming language done through a compiler" is yes? If so, then I believe you should write it as an answer. $\endgroup$ – bellpeace May 10 '16 at 20:36
  • 4
    $\begingroup$ @reinierpost: A house that was not designed by an architect is still a house. But what sort of a house would you prefer to live in? $\endgroup$ – Andrej Bauer May 11 '16 at 7:10
  • 1
    $\begingroup$ The question as stated is ambiguous. Can a programming language be created by creating a compiler for it? Definitely. Is this the way to create a programming language? No, it is just one possible way. $\endgroup$ – reinierpost May 11 '16 at 13:50
  • 2
    $\begingroup$ @johan A programming language is of too big practical and theoretical importance to be left as a concept that is not precisely defined. For instance, how would you precisely explain to someone what is C or how it precisely works? By giving her a C compiler? But there are so many of them and they are different! Moreover, in many cases we don't even know what the C compiler will do (hints: concurrency, memory models). Strictly speaking, a compiler/intepreter ``induces" a programming language, but thinking of a programming language as a mere implementation raises more issues than it solves. $\endgroup$ – bellpeace May 11 '16 at 19:32
5
$\begingroup$

Say, I wanted to create my own programming language. Assuming that I have made all of the decisions about how I want it to look and act, do I just need to write a compiler for it?

No. Making all of the decisions about how you want the language to look and act is creating your own programming language. You don't need a compiler or an interpreter to create a programming language. You don't need a compiler or an interpreter to write programs in your programming language.

You only need a compiler or an interpreter if you actually want to run the programs you write.

My question is, is the creation of a programming language done through a compiler? High-level is fine.

No. The creation of a programming language is done through coming up with two sets of rules:

  1. what a legal program looks like (syntax)
  2. what a legal program does (semantics)

That's it.

There are programming languages which have no implementation. Or which had no implementation for a long time.

For example, Konrad Zuse created Plankalkül in the mid-1940s, but due to the war he never was able to implement it. It was first implemented as part of a dissertation in 1975. But it certainly existed in the 1950s and 1960s.

LISP was originally designed as a more tractable alternative to λ-calculus for studying computation. It was implemented by Steve Russell, a student of John McCarthy. McCarthy himself even doubted that LISP could be implemented at all!

APL was originally designed as a notation for teaching mathematics. It was later extended to serve as the specification language for IBM System/360. Implementations came later, after the language had already been used.

PLANNER was a very influential language, which was actually only implemented after it had already influenced other languages; it was designed in 1969 and implemented in 1973, at which time it had already influenced Smalltalk and Prolog (both 1972).

Structure and Interpretation of Classical Mechanics is a physics textbook which uses Scheme instead of maths to describe dynamic systems; the fact that Scheme has interpreters and compilers is inessential for the book, it is used as a language for conveying thoughts, not running programs.

As you can see, programming languages can be useful even without implementations. "Programs should be written for humans to read, and only incidentally for computers to execute" is a famous quote from Structure and Interpretation of Computer Programs. Programming languages are formal languages for unambiguously describing complex processes. The fact that if you describe a process precisely enough for a human to understand, it also happens to be executable by a machine is a side-effect. It's a very desirable, useful, powerful, side-effect, but it is a side-effect.

The very first "programming languages", λ-calculus, SKI-calculus, Turing Machines, μ-recursive functions, weren't created for execution. They were created for understanding fundamental questions of logic and mathematics.

$\endgroup$
0
$\begingroup$

Is the creation of a programming language done through a compiler?

There are 3 options.

  • An assembler
  • An interpreter
  • A compiler

Assembler
Source code written by a human translates 1 to 1 into machine code consumed by CPU.

Interpreter
A program reads each line of code, follows the instructions and executes these in order.

Compiler
A program parses the statements often using an Abstract Syntax Tree and uses that to generate object code.
The compiler generate some form of object code that can be consumed by a real or virtual machine.

Blurring the lines
There are lots of intermediaries here.
Ruby runs from its AST. Java famously runs byte code for a fictional CPU.
SQL is interpreted, but does not get executed as written, it gets translated into a query plan.

Javascript exists in a weird twilight zone. It is interpreted for the most part, but critical parts are run through a JIT-compiler generating non standardized byte code and it is also used as the object code for some compilers.
Php used to be a pure interpreted language, but Facebook uses it's own php compiler.

My recommendation
If you want to experiment with writing a programming language.
Start with an interpreter.

If you want to understand compilers, study AST's !.
A language like Pascal is tailor-made for an AST it can go from source to machine code in a single pass and thus is relatively easy to implement in a compiler.
If you insist on studying compilers and not interpreters I recommend you study Wirth's writings on the subject.

$\endgroup$
  • $\begingroup$ There are more than the three options. For example, one option is: do nothing. You can create a programming language simply by stating its rules. You don't need to implement them at all. Plankalkül wasn't implemented until 60 years(?) after it was created. LISP and APL weren't originally intended to be implemented at all, LISP was designed as a more tractable version of λ-calculus for studying computation, APL was designed as a notation for teaching mathematics. The book Structure and Interpretation of Classical Mechanics uses Scheme as a notation for describing dynamic systems, not as a … $\endgroup$ – Jörg W Mittag Dec 12 '16 at 22:26
  • $\begingroup$ language for writing programs that actually get executed. $\endgroup$ – Jörg W Mittag Dec 12 '16 at 22:26
0
$\begingroup$

All a compiler does is to ensure that the input it's given uses the language the compiler understands and that it carries the same semantic structure as the language.

The compiler fakes intelligence by making use a lexer and a parser in order to lexically analyse the input and try to parse the tokens into an order that has the intended meaning without introducing ambiguity.

To answer your question, you CAN create a programming language by creating the compiler, but in doing so, the programming language is actually created before the compiler is completed.

Think of programming languages as any other language out there - English, French, German, etc. The job of a compiler is, given some input, make sure the words used in that input match words used in the language it is built for, make sure that the ordering of the words make sense in the language it is built for and finally translate that input into a language that the machine can understand

$\endgroup$
  • $\begingroup$ This is not necessarily true. There are plenty of example of languages created along with the programs written to process them. FORTRAN was the name of the compiler, not the language. $\endgroup$ – reinierpost May 11 '16 at 13:52
  • $\begingroup$ @reinierpost My point is that before a compiler can recognize a set of tokens within it's given language, those tokens must exist first...hence the language has come into existence before the completion of the compiler. A language cannot exist without it's most basic components which are the words/phrases within that language. Semantics can come later. In much the same way, a compiler cannot even begin to pretend it compiles a language if it doesn't know the words that make up that language $\endgroup$ – smac89 May 11 '16 at 15:39
  • $\begingroup$ There doesn't need to be a 'given' language. The compiler can process input without any specific definition of what constitutes valid input for it. Try to get a crowd of C programmers to agree on what is and isn't a C program exactly. Good luck! $\endgroup$ – reinierpost May 12 '16 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.