Search code examples
ccompiler-constructionprogramming-languages

How do programmers make a programming language on top of C?


I am interested in making my own programming language on top of C, but I have no idea where to start.

So, I researched, this caught my attention:

A lot of languages are C-based. 

Popular programming languages like C++ and Objective-C, and possibly C# and Java are all built on top of C. (Not to mention Python)

How did C++ and Objective-C creators managed to make a new language that is C based, but add object oriented programming concept added?


Solution

  • C based does not neccesarally mean that it's interoperable with c. It can just mean, that it uses the same paradigm or similar syntax like egyptian bracets.

    Java is C based but also borrows from Smalltalk and it cannot run any of C code. C++ can call C functions because it's compiler produces the same binary code as C code. Once you have linked their binaries they become interoperable. Pythons implementation CPython does not produce any binaries first, it's an interpreted implementation, meaning it is run by an interpreter Programm which holds the whole parsed syntax tree in memory. And because the Interpreter is just a C programm itself, it can call other C functions. So there is no such thing like adding features in top of C. Those are different languages, with differen compilers/interpreters and grammatics which just borrow some of the grammatical rules from c.

    The easiest way to start creating an own language, is by using a parser generator like antlr. And i would start creating an interpreter and not a binary compiler. Perhaps a compiler, which compiles to c. Knowledge about language grammatics is essential.