Writing a Programming Language...

Discussion in 'Mac Programming' started by ArtOfWarfare, Jul 28, 2013.

  1. ArtOfWarfare macrumors G3


    Nov 26, 2007
    With each language I learn, I find new parts that I wish were in others, and I find that typical parts that I like are missing. I assume everyone who knows more than 2 or 3 languages probably feels this same way.

    What I'm wondering is... at some point, should I write my own programming language that has all those features I miss when I change from language to language?

    IE, my favorite part of Obj-C, which is kind of present in Python but not really (and isn't in any other language that I've learned so far), is the inmethod arguments. But at the same time, I like how Python has ditched a lot of confusion snags, IE, what is the difference between nil, null, and NULL? When do I use switch/cases? (Python's answer to most questions like that is simply removing incorrect answers.)

    Has anyone else here ever written their own programming language? Was it worth the effort? I've heard that supposedly only 2% of programming languages ever get to the point where they're used by anyone besides the original creator of it.
  2. Scrub175 macrumors 6502


    Apr 25, 2012
    Port St Lucie FL
    Even though I'm a very new beginner at programming, isn't the purpose of programming to get the computer to do what you need it to do? With that said, creating a new language is precisely what you should do if current languages can't or don't do what you need. Programming solves problems so a new language would be the answer.
  3. mrichmon macrumors 6502a

    Jun 17, 2003
    What makes the answers incorrect? The Python community generally presents the argument as the other languages are "incorrect" but in reality, it is a matter of taste and what the language designer(s) are trying to achieve.

    No one language is good for everything. No one language has sufficient expressibility or the right level of abstractions for all uses. This becomes particularly apparent when you move into supporting domain-specific languages to allow non-programmers the power that shallow programming in a particular domain provides.

    But given your questions about nil, null, and NULL, and "confusing" aspects of other languages I suggest that maybe Python is the first language where your understanding of programming has started to come together. You might want to get experience with other languages before venturing into writing your own. There are many common approaches to language design and it is worth understanding the paths that are already well trodden.

    Some key languages that take different approaches than Python, Objective-C, and Java are: Lisp, Haskell, Smalltalk, Self, Scala, Verlog, C++, Prolog.
  4. ArtOfWarfare, Jul 28, 2013
    Last edited: Jul 28, 2013

    ArtOfWarfare thread starter macrumors G3


    Nov 26, 2007
    Sorry, miswording on my part. Python decided to remove sticking points like that by coming up with a single solution and not having the others. They carefully debate the options, and pick one. In the case of switch/case, they decided to forgo it because the main reason it was introduced in languages like C is to take advantage of jumping between addresses in memory. Such a feature wouldn't actually help in Python, since it's an interpreted language. Java has it for little reason besides that C had it, as far as I can tell.

    I believe I am adequately familiar with this... nil / null / NULL, from what I recall, stems from C aiming to incorporate some features of C++ and Obj-C being determined to be a perfect superset of C. As a result, there's redundancy.

    I'm quite familiar with C++ and I've used Verilog in school... I've read some about Lisp. I suppose I'll look into some of those other languages.


    I'm reading all about smalltalk and finding it quite fascinating. I like a lot of the ideas and I'm surprised at how many of the ideas I had independently come up with that I thought would be unique to my language are actually in Smalltalk, but there's a good deal that I think my language will have that Smalltalk doesn't.

  5. InTheMist macrumors member


    Jun 22, 2013
    The closest I've ever come to this is writing an assembly compiler in Visual Basic. True.

    But I can fully understand where you're coming from. Objective-C has so many different types of syntax, it would be nice if that was all wrapped into one.
  6. Red Menace macrumors 6502

    Red Menace

    May 29, 2011
    Littleton, Colorado, USA
    Another thing you should realize is that anything you do will not come anywhere near the level of the mainstream languages, simply because you aren't going to be able to put anywhere near that amount of time into it.

    I know a few guys that use a language that was home grown long, long, long ago. They still use it today probably because they are intimately familiar with it, but it is light weight and pretty good for what it is. I suppose it comes in handy to be able to just whip out the source code and tweak it for some new feature, but this kind of thing looks to be fading fast.
  7. ArtOfWarfare thread starter macrumors G3


    Nov 26, 2007
    For a compiler I plan on writing it so that it can compile down to C, and then letting a C compiler compile it into machine language. I also plan on having some sort of command line interpreter like Python has.
  8. robvas macrumors 68030

    Mar 29, 2009
    Are you going to be building real features into this language or is it just things you can abstract in another language?
  9. ytk macrumors regular

    Jul 8, 2010
    If you want to do it for your own education or as a hobby, go nuts. Otherwise, no.

    MacRuby supports calling methods with inline arguments (not that I really think it's a great way to do things). And as of Ruby 1.9, you can pass pseudo-arguments to a method via a notation that makes it look like they're named arguments, but are really coming in as a Hash.

    Honestly, if you generally like Obj-C, but are unhappy with certain things about it, you really should learn Ruby (especially so if you're interested in Smalltalk, since many concepts in Ruby are lifted directly from Smalltalk). In fact, every Mac programmer should learn Ruby. I'd go so far as to say that, for the vast majority of purposes, MacRuby is a better Obj-C than Obj-C. Python is fine for what it is, but if you're using a Mac you owe it to yourself to learn Ruby.

    I haven't, but I've read a number of articles on TheDailyWTF about people who thought it was a good idea.

    Be thankful it's not higher. There are enough languages available today that we don't really need another one that simply improves a couple of annoyances some other language has. It would have to pretty revolutionary to warrant its existence.
  10. robbieduncan Moderator emeritus


    Jul 24, 2002
    Go look at LLVM. It is essentially a toolkit for building compilers. And has a good-quality Mac back-end...
  11. subsonix macrumors 68040

    Feb 2, 2008
    It makes the most sense if you have created a fairly complex program and want an alternative interface, a domain specific language will provide an arbritariness that is not possible by normal means. I guess a middle ground is to make a library or commandline interface.

    I don't think a general purpose makes much sense, there are already so many to choose from.
  12. ghellquist macrumors regular

    Aug 21, 2011
    Stockholm Sweden
    Designing and creating a computer language is great fun and a great learning experience. It takes a lot of work though to get the language up and running. Even a simplistic compiler without too much intellegence will include a large software effort and quite a few things to learn and code and debug. You have to decide if it is worth it.

    I have been down that road a few times, but none of my efforts has survived for long.

  13. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    Creating a toy programming language and a functional compiler or interpreter for it is about a medium hard quarter or semester long project in an upper division CS class. I've done that... once for school, and once for "fun".

    If you search the web, you'll find a few implementations, tiny/toy Forth, Lisp/Scheme, Basic, Pascal, etc. interpreters of several hundred to a few thousand lines-of-code.

    One easier way to get started is to play with the C pre-processor, or adding a more sophisticated pre-processor on top of that, to create your language. That's how the earliest developments of C++ and Objective C actually got started.
  14. ChrisA macrumors G4

    Jan 5, 2006
    Redondo Beach, California
    If you just start adding features you get a mess. Better idea is to remove every feature you do not need.

    Some examples are PL/1 which had every feature then known. On the other end of the spectrum we have Lisp, which is syntactically minimum.

    If you want one that makes sense and was well thought out look at Ada

    But if you want to do something useful that work on specialized languages for a specific purpose. It turns out if you can make the structure of the language fit the structure of the task then you reduce the effort to create programs. So the trick is to select a task area like say Computer Vision. Or natural Languag Processing. When you narrow the application area down like that then you can invent something.

    Trying to re-invent a general purpose language like C++ or Perl is ony goig to create more un-used compilers.

    Yes LOTS of people do this. Compiler writing was a required class for Computer Science students. And of course one of the projects in the class is a compiler, usually a very simple one.

    But pick a subject area that you know well, games, robots, signal processing, whatever and write a very narrow language. It many cases you can make it (like SQL) not executable, but really it specifies the problem, or what the rest should look like.
  15. ArtOfWarfare thread starter macrumors G3


    Nov 26, 2007
    I've been brainstorming for the past few days about this and at this point, I have something that borders on looking like an esoteric language. But only because I threw out just about every syntax I was familiar with and started from scratch. I'm wondering if I should put assignments back into my language... and return values...
  16. 960design macrumors 68030

    Apr 17, 2012
    Destin, FL
    Yes. I've written several compliers and several languages for custom

    Not sure how to answer this one. Yes? Just about everything I do 'was' worth the effort. You should have tasted the egg-drop Ramen I just made! Most definitely worth it.
  17. mslide macrumors 6502a

    Sep 17, 2007
    Why bother? If this is purely for academic reasons, then go for it. Otherwise, don't bother. The world doesn't need more programming languages. There's already too many of them that are virtually identical aside from syntax and semantics. After all, just about any problem can be solved with just about any language.

    If it were me and I had a lot of spare time to learn something new, then I'd spend it becoming more of an expert in areas that would further my career.
  18. dyrer macrumors member


    Feb 24, 2010
    There is no perfect program or perfect programmer, always there BUGS :roll eyes:
    Try to improve your skills, give a try more languages (as already mentioned here) there are plenty of them.
  19. haley01 macrumors newbie

    Jun 21, 2013

    Hey....I am fresher in development. Writing a programming language is very tough job. Could you please share something more knowledge with us.
  20. ghellquist macrumors regular

    Aug 21, 2011
    Stockholm Sweden
    Sorry, this is not really fit to be answered in this forum. I actually suggest instead using google and search for "write compiler". One of the first answers there has a long list of references. Many of them are written a lot better than I can (not beeing modest, only realistic).
  21. xArtx macrumors 6502a

    Mar 30, 2012
    So long as it's not interpreted live on the platform.
    Worked with one of those to try to write a program with it,
    couldn't even receive on the serial port because the interpreter couldn't poll it fast enough.
  22. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    I started out by reading a few textbooks on the subject (computer languages and compiler construction). Then I took apart and rewrote portions of some small toy languages for which I found short enough source code on the net (a tiny Scheme interpreter, IIRC) to read the entire thing.


    Ha. One of my slow toy language interpreters now runs about 100X faster (polling, etc.) on an iPad, than did my best hand-coded and optimized assembly language on a Mac Plus.
  23. ChrisA macrumors G4

    Jan 5, 2006
    Redondo Beach, California
    As I wrote above, it you pick a narrow task domain, say "computer vision" or "signal processing", or "robot control" and then design a language just for that task. Now you've made working in that task area MUCH easier then using some general purpose language like C++ to control robots.

    This is likely the only productive use of new languages and even then you'd be better off extending something that already exists.

    SQL is a fine example of this. It is nearly perfect for the very narrow task of searching a database. For example "select a, b, c where a > b" is very easy to write and to understand and is SO MUCH simpler than writing code in C++ to search a file of data.

    So your robot control language might just allow the user to specify and end condition and to put constraints of the movement. This would make programming easy.

    A language for signal processing you not have data type like integers and strings. You would have "streams" as you data type and operators for filters and resampling and conversion from time and frequency domains. The language would operate on much higher level objects and so the user would not need to write a lot of code for common DSP tasks.

    That is the "secret" of designing a good language, defining data types that are a good fit to the task and then good operators on those types.
  24. jtara macrumors 65816

    Mar 23, 2009
    "writing a programming language" is a rather ambiguous term. One might define a new programming language, implement one (once defined), or both.

    I've implemented one twice, and defined and implemented once, and 30-so years ago. One presumes the tools needed to do this are easier to use today...

    First time was a Computer Science course. We had to implement a compiler for a language that was defined by the instructor. We implemented in PL/1. (What's *that*, LOL!)

    Later, I defined and implemented a new language, called VSL, or "Variation Simulation Language". I think this is a good illustration of a legitimate need for a new language. This type of usage is known today as a Domain-Specific Language, or DSL. (Though the term was not yet in use at the time.)

    I was working for a company that had a product called VSA - "Variation Simulation Analysis". The had gotten rights to the product from a university professor who had implemented it on a mainframe. This had originally come out of work done at Willow Run Labratories during WWII. They had used the classic "room full of women on mechanical calculators" to do this analysis, and was certainly a contributing factor in our being able to churn-out thousands of airplanes for the war with minimal assembly difficulty.

    The product has changed hands several times since then, and it still exists today, 30 years later. It's part of Siemen's Team Center Lifecycle Visualization:


    In fact, it's the most popular software used today to perform this type of analysis, and it's been used to help design just about every high-tech complex mechanical product we use, from cars to aircraft to disk drives. I have no idea of VSL is still in use "under the hood" as it's all been long-since made into visual point-and-click operation.

    The problem at the time (30 years ago) was that mechanical engineers had to write models in Fortran. Fortran is cumbersome, especially when dealing with multi-dimensional arrays, and mechanical engineers don't generally write very good Fortran code. (Sorry, they are mechanical engineers, not programmers...)

    So, they would write a model, then they would have to link it with a static library. (VSA was written in Fortran.) This took about 1/2 hour. (linking compiled object code took a lot longer back then - typically much longer than compiling!) Then, they would discover a mistake and try again.

    What I did was a two-step process. First, I defined a simple stack-based interpreter, and implement it in Fortran. It would read a file into an array, and execute simple instructions.

    Then, I defined a language specific to the task. It made it very easy to deal with the kinds of things needed for these models - points, lines, planes, assemblies, etc. - and for manipulating them, join, move, etc.

    Then I wrote a compiler for VSL using C and the classic Yacc/Prep/Lex stack.

    Now a program could be compiled in a short time (maybe less than a minute) and there was no need for the lengthy link step, since now a pre-compiled program could be used that just read the output from the compiler (the interpreter code) and execute it.

    Programs ran quickly, because most of the time was spent in complex math-related library functions, which were all written in Fortran. The time spent in program logic (branching, loops, expressions, etc.) was minimal vs. the time spent in the math library.

    Use of VSA skyrocketed after that, due to the increase in productivity - the time needed to create a model was now a small fraction of what it had been. Early uses were, for example, to move from mouting hoods using slots (and having to carefully adjust the alignment of the hood during assembly) to using simple drilled holes. Gaps around windshield glass were eliminated and trim replaced with caulking material, as the windshield opening could now be designed to be more precise. Engine pollution levels could be predicted before actually building any engines, speeding the process of complying with new emission regulations.
  25. xArtx macrumors 6502a

    Mar 30, 2012
    Hehe.. nice to hear.
    My first effort resulted in a micro controller between a GPS and the receiving
    device to buffer the serial data, and retransmit it at snail pace so the
    interpreter could catch every character:


    There was never a version 2... I discovered the native language was C,
    and did the vector based GPS.

Share This Page