views:

1264

answers:

30

Possible Duplicate:
Simplest language to make an interpreter for

I'm wondering what the simplest programming languages are, excluding Basic and Brainf**k?

With that I mean a simple and easy to parse Syntax and a small standard library. I'm not looking at esoteric stuff, I assume "Turing completeness" is what I want.

(I'm asking this for a research project about implementing a programming language, so it's not so much about how many people use it. I'm not looking for Compiler Theory etc., I'm really just trying to find a simple language to implement as I don't want to invent my own just yet)

+12  A: 

Logo is another simple language. Mostly known for turtle graphics.

EDIT: removed Python because it was a poor suggestion! :)

townsean
I love Python, but it's anything but simple.
Ignacio Vazquez-Abrams
How is python small?
leppie
Python isn't exactly "easy" to parse or implement.
casablanca
well I guess it's just one of the more simplier ones I've used. :)
townsean
Then you just haven't gotten very far in it.
Ignacio Vazquez-Abrams
@townsean: You know the question was about easy to implement, not easy to use, right?
sepp2k
Well it's true I'm still a newb :)
townsean
So I heard the hare retired...
BoltClock
Python has a massive standard library. I do consider the standard library a part of the language :) (Upvoted for Logo though, added to the list of stuff to investigate)
Michael Stum
ZOINKS someone co-opted my answer!! :)
Vivin Paliath
+20  A: 

I guess many would not disagree if I say R4RS Scheme.

leppie
Of course they wouldn't, since most wouldn't know what it is ;)
KevinDTimm
Indeed, can't argue with that.
Pascal Cuoq
+1. Ironically, LISP fanatics might get offended stating that their language has no syntax :-)
André Caron
No Syntax ne Simple
KevinDTimm
@andre, (on the contrary ((they) might be delighted) (to assert that (LISP has no syntax))).:) (and that it is all about semantics. syntax just gets in the way)
alvin
@Andre, alvin: I agree, it having no syntax is both true and non-offensive to Schemers at least
Claudiu
@alvin: If only you wrote this in prefix notation, it would be *epic*.
delnan
+9  A: 

Forth.

Ignacio Vazquez-Abrams
There is a pretty well documented Forth interpreter here, not that there aren't others. http://www.annexia.org/forth
Pascal Cuoq
+7  A: 

Scheme and Lisp in general are quite easy to parse and implement.

Mikael S
They are quite easy to parse, but not to implement. Many require some "advanced" features, e.g. tail recursion detection, dynamic scoping, continuations, multiple-method dispatch, etc. R4RS Scheme is one of the "simplest" specifications though.
notnoop
True that, thanks. :)
Mikael S
A: 

Groovy is pretty simple.

Kaleb Brasee
I wouldn't think so. Again the question was about languages that are easy to implement, not easy to use.
sepp2k
LOL, haters gonna hate.
Kaleb Brasee
+1  A: 

"Jack" from The Elements of Computing Systems is an extremely simplified version of Java and is pretty easy to implement. The language was designed for easy implementation for the project presented in that book.

Dinah
+1  A: 

If you're trying to implement a language for a compiler, think of what makes the language difficult: the greater the number of states in your machine, the more difficult it is to program. I imagine there's also a corresponding increase in grammar complexity with the number of states that you can implement.

So while some may say "this language is simple, try it!" that won't really help you. You need to do an objective study of how many operators (for this colloquial explanation, let's include key words in with operators) a language has, how many ways that operator is overloaded, and how many exclusion cases there are for these operators (including which direction the exclusions run to determine the feasibility of implementing the exclusion).

my recommendation would be to examine wikipedia's link text and examine them and make this decision for yourself. Only you know your skills and toolset.

San Jacinto
+13  A: 

Lua is pretty small and fast (with LuaJIT).

hluk
That's what I'm going with right now. I looked at most of the languages, and Lua has a) a relatively simple syntax, b) a small standard library, c) a freely available spec (the printed spec is also cheap) and d) a lot of 'real world' uses. It's a purely subjective decision of course.
Michael Stum
+3  A: 

Unlambda is a very simple functional language.

Bart de Smet wrote a C# interpreter for it on his blog.

You might find it interesting even if it's not really what you're looking for.

fearofawhackplanet
Interesting. Bart is right about the brain damage part, but the whole Expression/Delegate stuff is useful to know.
Michael Stum
+4  A: 

Smalltalk has the smallest set of reserved words of all programming languages I know about and everything is an object, so you don't need to implement a type system. You could start small and build your own interpreter (perhaps in Smalltalk itself). Maybe you want to have a look at Squeak (http://squeak.org), which BTW is cross platform.

ofi
You must not know of Scheme then :)
leppie
dang! you beat me to it!
Joe
Per alan kay:"With as much panache as I could muster, I asserted that you could define the "most powerful language in the world" in "a page of code." They said, "Put up or shut up." http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html
Joe
@leppie A little bit in former times at the university, but I never could get the hang of prefix notation ;)
ofi
A: 

depends on what you're looking for... the pure lambda calculus is turing complete and simple to parse: It's just parens, lambdas and variables.

It IS kind of hard to use though... defining the integers is a little tough if you haven't seen the formulation before...

if you're going to actually USE the language, I'd say look at a bunch of school's compilers classes... there's bunch of toy imperative languages out there that people use... We used one called (I think) ASL: A Silly Language...

Brian Postow
A: 

Forth and Lisp are both very simple to parse. Forth is easier to implement though.

swestrup
+2  A: 

Learn how to use what the gods (Intel, AMD, Motorola, Freescale, Atmel, Cypress...) gave you.

Assembly.

Nick T
could you add some modern day references to get started? i haven't done assembly since the 6502 and would like to revisit.
Gabriel
@Gabriel: Most of the programming I do is on embedded MCUs (HCS08, AVR, PIC), so the specific vendors (Freescale, Atmel, Microchip, respectively) have a great deal of helpful literature in the form of App Notes to peruse through, but they are very MCU specific. I haven't dug into x86 at all.
Nick T
+1. Assembler isn't as easy as an HLL, but it is simple (at least, as long as you are only trying to do simple things with it :-). I'd suggest ARM as a good assembler to start with - being RISC it's extremely quick and easy to learn, very consistent and logical, and ARMs are in almost everything these days, so it's well supported.
Jason Williams
...I wouldn't exactly consider writing an assembler a challenge. Part of the challenge of writing an interpreter or compiler is fitting the syntax into a grammar. Assembly programs don't really fit into a grammar, unless you consider each line as a single program.
San Jacinto
+1  A: 

I think Prolog qualifies as one of the smallest Turing-complete programming languages. One of the idiosyncrasies of Prolog that may put people off is that looping is not given its own language construct like for or while in C, but is supported instead via tail-recursive predicates. Rather than thinking of Prolog as esoteric however, I consider it elegant and woefully underutilised.

I have developed neat meta-programming solutions with Prolog. Where the main application (in C++ say) translates an abstract definition of a problem into a Prolog application at runtime, which is then delegated to; often writing equivalent functionality in C++ would take forever. This is a good reason to learn and work with small/toy languages that do not merit immediate attention as general-purpose tools.

As a starting point for implementing your own Prolog engine look into Warren virtual machines.

landstatic
Its been a while but back in college when I used Prolog I remember thinking the downside was I ended up thinking of nice solutions to problems in theory that ended up performing horribly. What's a modern day Prolog implementation you use?
Gabriel
Indeed, judicious use of the cut predicate is the order of the day with Prolog, oh and providing sufficient stack space for the threads running the interpreter. I had a really good experience with IFProlog http://www.ifcomputer.com/IFProlog/ but it looks like support for C++ is no longer available.
landstatic
A: 

If you just want to code functions the absolute simplest programming language I've ever come across (which is also very useful) has got to be TCL.

If you want to do object oriented programming, I would go with a different choice, preferably one does not fall into the category of "has object oriented extensions".

Personally I don't think it gets much simpler than (simple) C#, although I'm really only comparing it to c++ and java.

Gabriel
A: 

Miranda is a pretty easy to learn programming language.

Eros Nikolli
Seems like this question is turning into a nostalgia trip. Miranda brings back fond memories for me.
landstatic
+2  A: 

Mumps should be simple to implement. Not a lot of bells and whistles.

Ravi Gummadi
Mumps, long time no see! Is there still any implementation around besides cache?
Fernando
Not sure. The only major vendor still around is "Intersystems". :)
Ravi Gummadi
+4  A: 

LOGO was the very first programming language that I ever learnt. As I found out later, it is a dialect of LISP.

It is a very simple language and great for beginners. At least, it was awesome for me at the time. Thinking back, I guess I was doing functional programming without even know what functional programming was... or even what programming was.

As far as implementation, it should be pretty simple to implement.

Vivin Paliath
I also learned this first in grade school. In retrospect I think one of the benefits of starting with a language like Logo is that its visual and you get the encouragement of seeing cool geometric patterns and colors made from your code - compared to other langs that have more boilerplate before you actually see more than ..a console output.
philip
@philip Very true. I learnt LOGO when I was 9 or 10 - so 4th or 5th grade. It was pretty awesome getting immediate feedback via the pictures. It also introduced recursion in a pretty neat way because I would use recursive algorithms to draw pretty pictures (like spirals or whatever). At the time I had no idea I was even doing recursion.
Vivin Paliath
+1  A: 

I would definitely suggest Python!

Antonis
The Problem with Python is the massive Standard Library: http://docs.python.org/library/ (Which I consider a part of the language)
Michael Stum
@Michael: A large part of the standard library is written in Python, so a fully working Python implementation gets these "for free". And I believe with the C API documentation and a FFI for the language you use for the implementation, it *should* be possible to get the compiled extensions working, too. Still, the language is not as simple (to implement) as suggested here.
delnan
It's easy enough to separate it from the language itself though. Also, most of the standard library is written in Python (or has an alternative Python implementation, e.g. inside the PyPy project), so you should be able to use those once your Python implementation is done. (Edit: seems like I forgot to refresh the page and delnan already mentioned this, still the reference to PyPy might be useful.)
JanC
+2  A: 

I'd try Brainfuck first. Yes, it's an esoteric language, so it's not very useful in itself. However it should be very easy to implement, as it was designed to have the smallest compiler possible.

Vilx-
Thanks. I should have added that to the question - I have already done Brainfuck :) http://www.stum.de/tag/brainfk/
Michael Stum
+1  A: 

Depending on your definition of "simple", SKI Calculus definitely qualifies, as it's an abstract model of computing, specifically a reduced kind of lambda calculus. It's turing-complete, and very very simple.

Zarkonnen
+4  A: 

Pascal is fairly simple and Basic-like in its emphasis in readability.

Gabe Moothart
+1  A: 

Koi is a simple language to understand and implement. It was designed with this in mind -- see the description on the link.

absynce
+1  A: 

OK, since nobody has mentioned it, here it goes: Snobol4. It's simple (really simple), weird (REALLY weird) and surprisingly powerful.

Learning it was like finding the remains of an advanced alien civilization in my backyard.

Fernando
+1  A: 

commonLISP / Scheme.

They do not even differ between data and code. The syntax consists nearly only out of brackets.

To implement an interpreter/compiler for these laanguages does mean:

  • to implement or to use an existing garbage collector and
  • to ensure "proper-tail-calls".

To learn those languages is pretty easy. As soon as you understand to program with/in lambdas (anonymous functions), you understand the basics of functional programming.

comonad
A: 

PCF

swegi
A: 

I think the easiest there is is Jon Skeets Hello World language. It can't get any simpler than this

Default
Nonsense. http://esolangs.org/wiki/Nil is much simpler.
delnan
Indeed, and both are not turing complete ;)
Michael Stum
@delnan: that looks interesting :) I found the interpreter: `Jon Skeets Hello World language is not turing complete` compiles [email protected]: whoops, I forgot to look at all of the requirements.. It was late last night
Default
A: 

If I were in your case I would like to implement my own version of a declarative language, now days declarative languages (and functional languages also) are becoming the most popular, first because their usage is very simple, after because you write small code with them, and finally because the usage of XML is for now so extended. For example Microsoft XAML, XSTL, XSL-FO and my favorite JSTL:

Why you don't write some interpreter of JSTL, I don't think it could require the most complex code to be parsed, could it?

<c:choose>
    <c:when test="${param.action == 'my_id_command'}">  
        <%int col=0;
        String strElements = request.getParameter("icount");
        int iElements = (int)Integer.valueOf(strElements).intValue();
        %>
        <c:set var="continue">yes</c:set>       
        <%for(col=0; col<iElements; col++){%>
            <c:set var="c"><%=col%></c:set>

            <sql:query var="dtcount">
                SELECT family_name
                FROM  families
                WHERE family_name = '<c:out value="${paramValues['arr_family_name'][c]}" />'
            </sql:query>        
            <c:if test="${dtcount.rowCount>=1}">
                <span class="sqlbadresult">
                    xxx  FAIL: key value [<c:out value="${paramValues['arr_family_name'][c]}" />] already exist  xxx <br/>
                    xxx  0 items added  xxx
                </span>
                <c:set var="continue">no</c:set>
            </c:if>
        <%}%>

        <c:if test="${continue=='yes'}">
            <sql:transaction>           
                <%col=0;%>
                <c:forEach items="${paramValues.arr_family_name}" var="pval">
                    <c:set var="c"><%=col%></c:set>
                    <sql:update var="updateCount">
                        INSERT INTO some_table(
                                        group_name,
                                        family_name,
                                        description,
                                        reg_date
                                    )VALUES(
                                        '<c:out value="${paramValues['arr_group_name'][c]}" />',
                                        '<c:out value="${paramValues['arr_family_name'][c]}" />',
                                        '<c:out value="${paramValues['arr_description'][c]}" />',
                                        '<c:out value="${fDate}"/>'
                                    )
                    </sql:update>
                    <%col++;%>
                </c:forEach>
            </sql:transaction>

            <sql:query var="dtcheck">
                SELECT reg_date 
                FROM some_table
                WHERE reg_date = '<c:out value="${fDate}"/>'
            </sql:query>
            <c:if test="${dtcheck.rowCount == param.icount}">
                <span class="sqlresult">
                    !! <c:out value="${dtcheck.rowCount}"/> rows inserted successfully !!
                </span>
            </c:if>
            <c:if test="${dtcheck.rowCount != param.icount}">
                <span class="sqlbadresult">xxx transaction failed xxx</span>
            </c:if>             
        </c:if>
    </c:when>
<c:choose>
ArceBrito
+3  A: 

I'm surprised nobody has mentioned Small Basic, its basically a new BASIC for kids by microsoft.

From my answer from this question http://stackoverflow.com/questions/2422541/matlab-for-kids/2427357#2427357


What about trying Small Basic Its a reduced language (i think only 15 or so keywords) and has an IDE specially made to appeal young kids. It even includes the LOGO turtle drawing!

plus you can publish your projects as silverlight apps online with just a few clicks.

here's a link of a Hanselman post of his opinion on Small Basic, plus a little shape drawing app he made with it link text

from the blog:

While the boys are only 2 and 4, I'm always keeping an eye out on new ways to teach them programming. [...] Small Basic is a simple (only 15 keywords) but powerful environment for getting started programming. Great for kids and non-technical spouses, but powerful enough even for the professional game developer. [...] For those of us old enough to remember learning to program with LOGO and its ubiquitous Turtle.

(pics from Scott's blog) alt text LogoTurtle

Francisco Noriega
A: 

I simply recommend C.

Sheagorath
Relatively simple to implement, but the standard library is a bit too big for my taste. Also, since it's highly platform dependent (long int can be 32-Bit? Madness!) it's not that simple :/
Michael Stum