Posts

Showing posts with the label shitjs

Let's make a shit JavaScript interpreter! Part Three.

Image
Let's put the Research into R&D. I guess it should be called Shit Research to go along with the name of this series (p1) of articles (p2) I started one year ago. It takes a lot of time to read over hundreds of thousands of lines of undocumented C++ and java code, so part three took much longer than expected. Let's explore existing JavaScript implementations. In this part we are going to take a small digression to look over other JavaScript implementations. I'll provide a short description of how each JavaScript implementation is made. We can use the Architectural knowledge from each implementation to inspire our own implementation. Another benefit of researching each implementation is that we can find all the different tools they use. For example different test suites. Make sure to read the URL's for each implementation to find out more information about each one. There is a list of ECMAScript implementations at wikipedia . We will not c...

Let's make a shit JavaScript interpreter! Part Two.

Image
Let's make a shit javascript interpreter! Part two. As a learning exercise, I've begun writing a JavaScript ECMAScript interpreter in python . It doesn't even really exist yet, and when it does it will run really slowly, and not support all js features. Homework from part One - A simple tokeniser. We ended " Let's make a shit JavaScript interpreter! Part One. " by setting some homework to create a tokeniser for simple expressions like "1 + 2 * 4". Two readers sent in their versions of the tokenisers (ps, put a link to your home work results from Part One in the comments, and I'll link to it here). http://pastebin.com/P0sXjr65 http://gist.github.com/460197 Our simple tokeniser operators = ['/', '+', '*', '-'] class ParseError(Exception): pass def is_operator(s): return s in operators def is_number(s): return s.isdigit() def tokenise(expression): pos = 0 for s in expression.split()...

Let's make a shit JavaScript interpreter! Part one.

Image
Let's make a shit javascript interpreter! Part one. As a learning exercise, I've begun writing a javascript ECMAScript interpreter in python . It doesn't even really exist yet, and when it does it will run really slowly, and not support all js features. So... let's make a "from scratch", all parsing, all dancing, shit interpreter of our very own! Teaching something is a great way to learn. Also writing things on my blog always gets good 'comments', hints, tips, plenty of heart, and outright HATE from people. All useful and entertaining :) Tokenising So to start with, we need something to turn the .js files into a list of tokens. This type of program is called a tokeniser. From some javascript like this: function i_can_has_cheezbrgr () {return 'yum';}; Into a Token list something like this: [ {"type":"name", "value":"function", "from":0, "to":8}, {"type":"n...