Added InputStream, Tokenizer, and Parser(unfinished) class. Changed Newerth to Aevum

This commit is contained in:
Daniel Xie
2016-11-14 00:42:31 -06:00
parent f311b0b84f
commit 40b0b585e1
7 changed files with 220 additions and 10 deletions
+25
View File
@@ -0,0 +1,25 @@
/* InputStream class. Creates a "stream object" that provides operations to read
* from a string. */
function InputStream(input) {
var pos = 0, line = 1, col = 0;
return {
next : next,
peek : peek,
eof : eof,
croak : croak,
};
function next() {
var ch = input.charAt(pos++);
if (ch == "\n") line++, col = 0; else col++;
return ch;
}
function peek() {
return input.charAt(pos);
}
function eof() {
return peek() == "";
}
function croak(msg) {
throw new Error(msg + " (" + line + ":" + col + ")");
}
}