This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Suggestions for writing a programming language?
I have used many programming languages and after several years of experience I have finally decided to make a language with my friends. I know that this is a task not for the faint of heart. We are devoted to the task and are going to make sure that this gets completed.
Now I wanted to start off by asking: what are the steps to writing a programming language? What should we start off with (ex. The parser)?
Any answer is helpful!
If this is your first language, then work on all parts of it at the same time, start with a mini language spec and extend it feature by feature. Unless a its a domain specific language you should use a language that comes close to what you try to implement so that later you might be able to write a conversion tool to get a bootstrapping version of your compiler.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to develop a simple C style scripting language for educational purposes.
Thing I have done so far:
defined syntax of the language
written code for tokenizing the language.
The features that I want to include at the moment:
Arthematics
Conditions
while loop (only)
At the moment I don't want to add other features to the language, as it will make development procedure quite complex.
However, I don't know what are the next steps that are involved in developing a language. I have gone through many questions on SO but they weren't very specific in detail. Kindly guide me with this process.
I think these answers are helpful starting out:
How to go about making your own programming language
How to develop Programming language like Coffee script?
If you have defined a EBNF grammar, then you can use a tool like BISON to create a parser. Using that parser to generate an abstract syntax tree you can then proceed to create an interpreter for your language.
Few years back I have been developing my own language too (it was interpreted language) and in phase when language was ready for "others" to try, I found out that there were few things I should have done earlier, or better:
Solve tons of simple programming problems in that language
Solve just a few, but I would call it "hard core" programming problems with it (for example Project Euler)
Write complex language specification, few examples, wiki or FAQ, well anything that will spare you answering the same questions all the time
Hope that helps.
Yes, having done this several times I know it's hard to know where to start. And you really don't need Lex or Yacc or Bison.
Make sure you have the definitions for your lexical elements (tokens) and grammar (in EBNF) nailed down.
Write a lexer for your tokens. It should be able to read a sample program emitting tokens and ending gracefully.
Write a symbol table. This is where you will put symbols as you recognise them. You can put reserved words and literals in here too, or not. It's a design choice.
Write a recursive descent parser, with a function for recognising each production in your grammar. You may need to modify your grammar to let you do this.
Write a tree/node manager for your AST (Abstract Syntax Tree). The parser adds nodes to the tree with links into the symbol table as it recognises productions.
Assuming you get this far, the final two steps are:
Walk the AST performing type and reference resolution, some kinds of optimisation, etc.
Walk the AST to emit code.
The last two steps turn out to be where most of the hard work is.
You will needs some specific references and what you choose depends on your level and what you like to read and what language you like to write. The Dragon Book is an obvious choice, but there are many others. I suggest you look here: Learning to write a compiler.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Disclaimer: Yes I know this will take 3 years, at least.
I am looking forward to writing a new interpreted programming language. I have a quite solid idea of what I want in terms of dynamicness, syntax, object model, etc, etc.
Now that I have the idea, I have a few questions before I start:
Should I begin writing the full specification and then implement, or write them both all along?
I'm still doubting between C and C++. C++ would allow for more clean design and faster development while C would (maybe) ensure portability to more platforms (microprocessors?). Performance is a must.
Should I try to interest people for the project before the first working prototype so they can cooperate (the end product will be a liberal license anyway), or keep working alone until I have something that runs?
How modular should it be? I am sure that I won't immediately start working on a bytecode interpreter but something easier to implement but slower thing first, so modularity is a must in order to be able to extend later, but I guess overdoing it will hamper performance and clearity.
The answers to your questions depend largely on why you're doing this- the primary reason. Are you trying to create the next Ruby, or is this a learning exercise?
Specification: If this is a personal project, this is not as important. PHP gets a bad rap for having been developed "on the fly," yet many people use it every day. A more complete spec will probably help get people involved if/when you want help.
If you want cross-platform and performance, C is the way to go.
If you want people to join in, prove something first. Write a killer-cool application with your language and blog/talk about why your language is different/special/better.
Modularity of what, the language itself or the compiler? If you want to extend the language, a good spec will help (see #1.) The compiler should be designed with all the best practices in mind, which should help make it extensible.
I hear the Dragon Book is good for learning to develop compilers.
Your specification will be broken unless you write it hand-in-hand with the implementation.
If you think C++ would give you cleaner design and faster development, you should probably use it.
You will have difficulty getting anyone interested in a project unless there is something that runs and demonstrates what is unique about your language.
If you think your language will ever require a byte-code interpreter (and you do say "Performance is a must") you should investigate the capabilities of existing byte-code interpreters before you finalize your language design.
I think you have set yourself too many goals. You say "performance is a must" but in a comment reply you say your goal is "to learn a lot about language design" and that it is "pretty unlikely" that you'll use it in a real project. New programming languages are created to solve problems; more precisely, they're created to help people express solutions to problems in better ways. Designing a language without using it seriously, intensely, continually is like writing software without any test cases: you're likely to wind up with something unusable.
If you want to try your hand at language design, then find a problem---one that you care about---that existing languages won't let you solve the way you want. Then do whatever you can to get a working implementation and start writing and running programs using it. You don't need a hand-crafted JIT compiler with a runtime written in highly bummed assembly code. If you target the JVM or .NET, you get a very high-performance GC, scalable threading system, libraries, and lots of other good stuff for free, even if it interferes with that awesome idea you had for ______.
On the other hand, if you just want to make something run fast, don't try to design a language at the same time. Just find one that you like, learn about implementation strategies, and see if you can do better.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have read a few articles on Internet about programming language choice in the enterprise. Recently many dynamic typed languages have been popular, i.e. Ruby, Python, PHP and Erlang. But many enterprises still stay with static typed languages like C, C++, C# and Java.
And yes, one of the benefits of static typed languages is that programming errors are catched earlier, at compile time, rather than at run time. But there are also advantages with dynamic typed languages. (more at Wikipedia)
The main reason why enterprises don't start to use languages like Erlang, Ruby and Python, seem to be the fact that they are dynamic typed. That also seem to be the main reason why people on StackOverflow decide against Erlang. See Why did you decide "against" Erlang.
However, there seem to be a strong criticism against dynamic typing in the enterprises, but I don't really get it why it is that strong.
Really, why is there so much cristicism against dynamic typing in the enterprises? Does it really affect the cost of projects that much, or what? But maybe I'm wrong.
The word "enterprise" doesn't really mean anything to me, so I'm just going to assume you're talking about large corporations.
Dynamic typing is just that: dynamic. There is no way to effectively statically analyze your program with a dynamically-typed language. Static typing allows developers to catch mistakes before ever compiling or running their code, something that is very important in the corporate world. It makes debugging much less of a pain and thus increases overall productivity (or that's what they argue, anyway). Static typing is also very important in a team setting because it allows your IDE to tell you how to use a method that you've never seen. These kinds of "hints" are very difficult, if not impossible, to achieve with dynamically-typed languages.
The other big thing is that dynamic languages are simply not as mature as static languages. Languages like C++, Java, and C# have been in use in the corporate world for years and years and years, whereas dynamically typed languages are just recently coming into play. There is a lot more code written in Java than in Python, and a lot more support for the former as well.
Note that I'm not arguing for either side. I personally prefer dynamically-typed languages because they allow me to write the code much more quickly and spend less time thinking about the problem, but I can see the appeal of languages like C# in a huge corporate environment.
It's probably more about what people are familiar with than anything else. From a manager's point of view, he/she needs a good reason to use a technology that:
May have never been used by the company on a project,
No one on the team has any experience with,
Does not (appear to) have the backing of a solid "Enterprise" company such as Microsoft, IBM, etc
These factors are especially important if the project needs to be maintained for many years down the road.
I am not defending this point of view, just pointing out that it exists and may be a source of this criticism.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm currently working on the topic of programming-languages and interpreter-design. I have already created several programming languages but couldn't reach my goal so far:
Create a programming-language which focuses on giving the programmer a good feeling when writing code in it. It should just be fun and/or interesting and in no case annoying to write something in it.
I get this feeling when writing code in Python. I sometimes get the opposite with PHP and in rare cases when having to reinvent some wheel in C++.
So I've tried to figure out some syntactical features to make programming in my new language fun, but I just can't find any.
Which concrete features, maybe mainly in terms of syntax, do/could make programming in a language fun?
Examples:
I find it enjoyable to program in Ruby because of it's use of code blocks.
It would be nice if you could include exactly one example in your answer
Those features do not have to already exist in any language!
I'm doing this because I have experienced extreme rises in (my own) productivity when programming in languages I love (because of particular features).
You mentioned Ruby in your question. AFAIK, Ruby is the only programming language, for which Joy is an actual, stated, explicit design goal. (In fact, it is the only design goal.)
The reason that Yukihiro Matsumoto was able to design Ruby this way, is that he already knew and used tons of programming languages before he started designing Ruby and learned tons more in order to design Ruby. (Interestingly, he didn't know Python, and has said that he probably wouldn't have created Ruby if he did.)
Here's just a tiny fraction of the languages that matz has either used himself, or looked at for inspiration (or in some cases for inspiration what not to do):
CLU
Sather
Lisp
Scheme
Smalltalk
Perl
Python
Haskell
Scala
PHP
C
C++
Java
C#
Objective-C
Erlang
And I believe that this is one way that good programming languages can be designed (what Larry Wall calls postmodernist language design): Throw away everything that didn't work in the past, take everything that worked and combine that tastefully.
Of course, this requires that you actually know all those languages from which you want to "steal" and in particular, it requires that you know lots of very different languages with different paradigms, different concepts and different "feels", otherwise the idea pool from which you steal is rather small and inbred.
Consistency.
Its the feeling that you already know something when you use an API or feature you've never used before. It also makes you more productive as you don't have to learn something new for the sake of it.
I think this is also one of the Ruby 'likes', in that if you follow the naming convention, things start to 'just work' without bindings and glue and suchlike.
For example, using the STL in C++, many of the algorithms are the same for all containers - even strings. That makes it nice to use... except for those parts that do not follow the same API (eg vector of bools) then the difference is more noticable.
Two things to keep in mind are orthogonality and the principle of least surprise.
A programming language should make it easy to write correct programs and difficult (if not impossible) to write incorrect programs. For instance, in Java
long x = 2000000000 + 2000000000;
overflows, while
long x = 2000000000L + 2000000000;
doesn't. Is this obvious? I don't think so. Does anyone ever want something to overflow? I don't think so.
Hilarity.
http://lolcode.com/
Follow common practices (like using + for addition, & for bitwise/logical and)
Group logicaly-similar code in namespaces
Have an extensive string processing library
Incorporate debugging facilities
For a cross-platform language, try to minimize platform differences as much as possible
A language feature that appears simple and easy to learn surprises and delights the programmer with its unexpected power. I nominate Haskell type classes :-)
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Many programming languages introduce themselves with a simple "Hello World" program.
As a programmer, I must admit that this does not give very good insight into the strenghts and capabilities of the language.
What kind of problem would you suggest to use when providing a demo of a programming language?
I think the "Hello World" program has its uses. It says a lot if you can run that program:
You have your IDE/Tools setup correctly
You can write a class and or main method in that language
You can call a function in that language to print
You can edit a file and format it correctly for that language
Your compiler is working and you know how to use it.
So, for those reasons I don't find any better alternative to "Hello World."
However, in terms of a good intro to languages in general, I'm a big fan of coding challenges like Python Challenge. You are given a set of challenges/puzzles you have to complete with the language. They start out extremely basic (the first one is easier than writing a hello world).
They quickly progress into more difficult and advanced tasks, and usually are tasks that are intended to show off a particular aspect of the language.
I only wish every language had such a fun programming challenge. I think a LISP, Haskell, C++, C, Java, etc Challenge would be a fun introduction to the languages for people. They could be tailored to the languages.
The C++ challenge could quickly start having challenges involving pointers and other commonly misunderstood aspects to help drive home those difficult bits while the LISP/Haskell challenges could start to ask some questions that are more tailored to functional languages.
If you are worried about the scope of a "hello world" program, you can always upgrade to "hello universe"
IMHO, the purpose of the hello world program is to show a very simple program in that language, not to show the strengths and capabilities.
It would be hard as each language has its own strengths. Comparing a standard set of functions for each language might be asking for trouble, especially for an intro book.
Larry O'Brian wrote three very good blog posts on exercises to familiarize yourself with a programming language.
Part 1: Basics
Part 2: Data Structures
Part 3: Libraries, Frameworks and Mashups
"99 bottles of beer" is a slightly more involved example than "Hello world", so it can show the things that differentiate one language from the others.
Check out http://99-bottles-of-beer.net/ .
Depends on what core feature of the language sets it apart from other languages out there. The Haskell quicksort comes to mind.
With that said, hello world does show how to immediately produce some sort of output.
Personally when I start out in a new programming language I attempt to re-write a piece of code that I have already written in a different language so that I can get a feel for the language and see how it relates back to what I have already learned in my previous programming experiences.
People suggest programming simple stuff like binary search trees, and other data structures along with a simple way to test that it works. The other thing is to not give up on the programming language when things start to get complicated or do not fit in with your previous experience.
As for looking for the strengths in programming languages? Well, start out by writing a small application and then once you have a feel for the language look at open source projects written in this language. See what it does very well, look at mailing lists found out where the difficult parts were for that project, where they had to work around some idiosyncrasy in the language that caused them issues.
Certain languages you know right off the bat that they were meant for a certain task and using them outside of that task is not recommended. For example, PHP is a web programming language, the fact that you can write big programs in it and run them on the command line does not mean it is a language that should be used for those tasks.
I was very favorably impressed by Bjarne Stroustrup's choice to make a quite powerful calculator, including parsing. I expected that it would be too difficult as a first project, but he does an excellent job step by step. And the final application is not a toy.
All in his new book, Programming Principles and Practice in C++.
I some cases "Hello world" may be non-trivial.
See for example Struts 2 "Hello world". To have it working you'd need to have server set up, environment set up, your app deployed, etc.
Well a "blinky" is a good alternative, but that is more in the embedded world that this is relevant...
For you who have misses out on blinky, it is just to get a LED to blink on/off at steady pace. Kind of shows how to work with gpio.
/Johan