Wednesday, September 19, 2012

How to Create a Turing Complete Programming Language in 40 Minutes

Using a programming language is cool. Writing a programming language is cooler. Writing one in 40 minutes rocks! I just released a screencast on how to create a Turing Complete programming language in 40 minutes and 70 lines of code using my Babel Bridge parser generation gem and Ruby.

In this example I use my Babel Bridge parser-generator gem: homepage / github

Here is the 70-line-source-code from the screencast.


We continue to need fresh minds and new approaches to programming. There are many great challenges facing us in improving programmer productivity and supporting programming in our massively parallel age. I hope this screencast wets your appetite to pick up a parser-generator and play around with your own language. Maybe you'll invent the next Ruby, Java or Javascript!

6 comments:

  1. I just realized the linked source code is 78 LOC. It's 70 if you remove the comments... :)

    ReplyDelete
  2. Nice work! I have an issue when I am trying to run for: if 1<2 then 3 end. I receive a message error that it tells me that I don't have the evaluate method undefined. Could you help me resolving this problem? The code is the same with yours. Thanks!

    require "babel_bridge"

    class TuringParser , :>=, :==]] do
    def evaluate
    #res = left.evaluate.send operator, right.evaluate
    case operator
    when :<, :<=, :>, :>=, :==
    (left.evaluate.send operator, right.evaluate) ? 1 : nil
    #res ? 1 : nil
    else
    left.evaluate.send operator, right.evaluate
    #res
    end
    end
    end

    rule :operand, "(", :statement, ")"
    rule :operand, /[-]?[0-9]+/ do
    def evaluate
    to_s.to_i
    end
    end
    end

    BabelBridge::Shell.new(TuringParser.new).start

    ReplyDelete
    Replies
    1. You have no if statement in your code you pasted but that may be a typo I made a comment about this exact problem my self the solution is statment[0] and statment[1] in the if dec not match[1] and match[3]

      Delete
  3. From your article, and video students can learn easily. We have the skills to legally and efficiently collect evidence and solve the case. With our Private Investigators Irvine CA, desired assistance remains 100% guaranteed.

    ReplyDelete
  4. The tutorial is so nice. You tried to explain everything. For long distance moving services in Philadelphia PA, get our valuable services.

    ReplyDelete

Note: Only a member of this blog may post a comment.