//词法解析部分
let token = [];
let tokens = []
const start = (char) => {
if (char === '1' || char === '2' || char === '3' || char === '4' || char === '5' || char === '6' || char === '7' || char === '8' || char === '9' || char === '0') {
token.push(char)
return inNumner
}
if (char === '+' || char === '-' || char === '*' || char === '/') {
emmitToken(char, char); return start
}
if (char === ' ') {
return start;
}
if (char === '\r' || char === '\n') {
return start;
}
return emmitToken(char, char)
}
const inNumner = (char) => {
if (char === '1' || char === '2' || char === '3' || char === '4' || char === '5' || char === '6' || char === '7' || char === '8' || char === '9' || char === '0') {
token.push(char)
return inNumner
} else {
emmitToken("Number", token.join(""));
token = [];
return start(char);
}
}
function emmitToken(type, value) {
tokens.push({type,value});
}
console