JSReg javascript parser
Published: Thu, 22 Jan 2009 22:53:23 GMT
Updated: Sat, 22 Mar 2025 15:38:12 GMT
My host won't let me compile Spidermonkey on my server :( and I need a javascript parser for my next version of Hackvertor. I can't really afford a new server, so I decided to write my own :) It's nowhere near finished yet but I thought I'd give you a peak at the pre-pre-beta.
I use regular expressions (hence the name) to match parts of the string and return the relevant result. I'm trying a line by line approach and although at first I didn't think it would be possible it seems to be working well. It has no objects, conditions, arrays or even user-definable functions but it will parse basic math, strings, variables and call alert or eval.
I use instances of the parser within matches to further reduce the code and I've found matching parts of strings returning the result and continuing parsing is easier to code rather than trying to match the string as a whole. If it's a success I'll release it as open source, if not at least my regular expressions will have gotten better. I don't think it will be a full javascript parser but rather a simplified version of javascript but who knows.
A code sample and the demo url are available below:-
<pre lang="javascript"> x='12'+'3'; y=eval; y('alert(x)') </pre>