Skip to content

Instantly share code, notes, and snippets.

@cosinekitty
Created January 31, 2020 00:50
Show Gist options
  • Save cosinekitty/323319fe7c2f89f896b8ae2ded294624 to your computer and use it in GitHub Desktop.
Save cosinekitty/323319fe7c2f89f896b8ae2ded294624 to your computer and use it in GitHub Desktop.
The Token class represents each token in the input.
class Token {
constructor(text, index) {
this.text = text;
this.index = index;
// Classify the token.
if (/^[A-Za-z_]/.test(text)) {
this.kind = 'identifier';
} else if (/^[0-9]/.test(text)) {
this.kind = 'number';
} else {
this.kind = 'operator';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment