Intermediate to Advanced
Create a programming language of your own design.
No external tools like YACC, LEX, etc are allowed.
Must be programmed in C or C++ (the latter is preferred).
No "what I would do to C++/Pascal/FORTRAN/whatever if I could"
stuff. Make your own language design.
Must compile on Win32 and POSIX platforms (at least)
Signed and unsigned integer data types (including characters and booleans)
and mathematical operators: at minimum + - * /
Arrays (homogeneous data) and Lists (heterogeneous data)
Functions and procedures
Simple text I/O
Flow control statements: at minimum if
and logical operators: at minimum and
A floating point data type
User-defined data types
Binary file I/O (that is, files must be opened in binary mode;
the I/O methods themselves can be textual or binary or both)
Exceptions or Monads or some other form error handling
Make an interpreter for your language
Make a preprocessor to produce C or C++ compilable code
This is a very challenging project (hence the rating), but taken step by step it can be done by anyone who wants to. The hardest part will be understanding certain concepts fundamental to programming languages.
This challenge will be accompanied by a short series of tutorial-lectures that introduce and explore the aspects of this challenge. Those of you who take it up should feel free to post questions, comments, ideas, and expositions relating to the challenge in this thread. Also feel free to post your finished (and working) code as one of:
a hypertext link
a compressed and MIME-encoded copy if less than 8000 characters.
I prefer to keep to .zip
, or .tar.gz
compression archives so that everyone can open them easily.
to MIME encode.
You can use all the facilities of C and C++ that you are aware of, but you may not simply pass them into your toy language. For example:
cout << "foo\n"
is forbidden in your language, because it requires no effort on your part. Make the language yours
Decide which method
you wish to use to implement your language.
(Unless you are a total wiz, I recommend you stick to creating an interpreter.)
Start with the requirements
and work your way down the list.
(That is the order in which I will present the tutorials.)
Before you actually start coding, design what your language should look like.
For example, I may want to create a simple calculator language. It might be as simple as:
| integer x y|
print "Enter two integer numbers: "
x y = input integer integer
print "The sum is " + x y
This is pretty easy to parse (though there are a few interesting twists in there).
Finally, you should write a program (in your language) which demonstrates the features of your language. Suggestions are:
(easy) A simple calculator
(easy) A tick-tack-toe/noughts and crosses game
(medium) A program that adds, multiplies, and simplifies fractions
(hard) A program that takes a list of integer pairs and a number
and determines whether the number can be summed by taking one or
zero of the integers from each pair in the list.
SDL Graphics (very hard)
The tick-tack-toe/noughts and crosses game
The "pong" game
A fractal image generator
Well, that's all for now. The first tutorial will be coming soon!
Feedback is most welcome!
[2008-08-22 22:12 revised the requirements as indicated below]