JS Syntactic Parser

2010-03-05

So I've been working on a Javascript parser the past week or two. Well, I've been doing more than that, but results from the parser is at least something I can show you :)

Below you can see an example of what the parser can spit out. It takes regular Javascript and parses it according to the Ecmascript 5 specification.

The result below shows you how the next snippet gets parsed on the syntactic level (!!) This means that it will also parse semantically invalid code (like 15abc). But that's perfectly fine for the syntactic parser.

When you hover with your mouse over a group it tells you what production it matched that group as. Due to the way recursion was implemented, certain productions seem to be overly tested. Don't worry about it :)

The parser results in a parse tree and from that tree the bunch of spans below are created. The next step will be the semantic parser. That one is going to be much harder... But I like that challenge!

More soon, I hope :) Hope you enjoy it!

Code: (JS)
var r = /b/,
f = function(){
return 'e';
};
function test(s) {
alert("h"+s+"llo\nworld!");
}
test("b".replace(r, f));



var r = /b/,

f = function(){

return 'e';

};

function test(s) {

alert("h"+s+"llo\nworld!");

}

test("b".replace(r, f));