Initial commit. Note that I'm using CommonJS modules and node purely to help me develop this. If this ends up being useful, I will likely distribute the entire package as a single JS file for easier consumption in the browser.

This commit is contained in:
wycats
2010-11-25 00:48:55 -08:00
commit 85fa2cb65f
8 changed files with 383 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
var Lexer = function() {};
Lexer.prototype = {
setInput: function(input) {
this.input = input;
this.yylineno = 0;
},
setupLex: function() {
this.yyleng = 0;
this.yytext = '';
},
getchar: function(n) {
n = n || 1;
var char = "";
for(var i=0; i<n; i++) {
char += this.input[0];
this.yytext += this.input[0];
this.yyleng++;
if(char === "\n") this.yylineno++;
this.input = this.input.slice(1);
}
return char;
},
readchar: function(n) {
n = n || 1;
var char;
for(var i=0; i<n; i++) {
char = this.input[i];
if(char === "\n") this.yylineno++;
}
this.input = this.input.slice(n);
},
peek: function(n) {
return this.input.slice(0, n || 1);
}
};
var Visitor = function() {};
Visitor.prototype = {
accept: function(object) {
return this[object.type](object);
}
}
if(exports) {
exports.Lexer = Lexer;
exports.Visitor = Visitor;
}