Skip to content

Instantly share code, notes, and snippets.

@cosinekitty
Created January 31, 2020 00:48
Show Gist options
  • Save cosinekitty/d724e6f6d03f758e40d0e19ed43d5b83 to your computer and use it in GitHub Desktop.
Save cosinekitty/d724e6f6d03f758e40d0e19ed43d5b83 to your computer and use it in GitHub Desktop.
The Parser constructor does all the tokenizing
class Parser {
constructor(text) {
this.nextTokenIndex = 0;
this.tokenList = [];
const reToken = /[0-9]+(\.[0-9]*)?([eE][\+\-]?[0-9]+)?|[A-Za-z_][A-Za-z_0-9]*|\S/g;
for(;;) {
const match = reToken.exec(text);
if (match === null) {
break;
}
this.tokenList.push(new Token(match[0], match.index));
}
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment