Created
January 31, 2020 00:48
-
-
Save cosinekitty/d724e6f6d03f758e40d0e19ed43d5b83 to your computer and use it in GitHub Desktop.
The Parser constructor does all the tokenizing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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