0

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?

James
  • 176
  • 1
  • 4
  • 16
  • 5
    I regret to say that a proper answer to this question would be book-length. And I don't know of any existing books that answer it. – zwol Jun 18 '14 at 00:15
  • 3
    Welcome to SO. That is a very big topic, and probably not the types of questions answered here. Please read [ask]. Thanks. – OldProgrammer Jun 18 '14 at 00:16
  • extending C and similar syntax are not the same. – kenny Jun 18 '14 at 00:16
  • 4
    "Built on top of C" is *very* misleading for languages like C#, Java, and Python. – user2864740 Jun 18 '14 at 00:16
  • Look into [`flex`](http://flex.sourceforge.net/) (or `lex`) and [`bison`](http://www.gnu.org/software/bison/) (or `yacc`) if you're interested in creating a language. – ooga Jun 18 '14 at 00:17
  • 2
    "Based on" is ambiguous here. I think you should research the difference between a language that is /implemented/ using C, and one that is stylistically influenced by C. – crennie Jun 18 '14 at 00:18
  • http://stackoverflow.com/questions/13537/bootstrapping-a-language – sarnold Jun 18 '14 at 00:18
  • 1
    It sounds as if you are conflating the *design* of a language borrowing elements from C, the *implementation* of a language being written in C, and the *compiler* (if there is one) for a language producing C as output. C++ is nearly a superset of C-the-language, but there are many C++ compilers, some written in C, some written in C++, and probably still others written in other languages; and while the original implementation of C++ (called Cfront) compiled to C, most extant implementations compile to assembly or machine code for a particular architecture. – Jon Purdy Jun 18 '14 at 00:19
  • Some possible options for you: - You can start experimenting with macros. C has very powerful system of macro expressions and you can use them to create your own "language features", producing new language dialect. Technically it'll be the same language, but you can add your own stuff to it. - Other, much more advanced option, is to study how the existing C-compilers work. Choose an open source C compiler, fork it and modify by adding your new language concepts. For doing this you should be a quite experienced developer, I must say – Aleksei Petrenko Jun 18 '14 at 00:20

1 Answers1

0

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.

dre-hh
  • 7,840
  • 2
  • 33
  • 44