This commit is contained in:
Asaki Yuki 2026-01-25 02:50:36 +07:00
parent e7ac672470
commit 406e71575f
6 changed files with 22 additions and 16 deletions

View file

@ -188,6 +188,18 @@ export function Lexer(input: string, start: number = 0, end?: number) {
if (Checker.isNumberChar(token)) {
while (Checker.isNumberChar(input[index + 1])) index++
if (input[index + 1] === "e") {
index++
if (input[index + 1] === "-") index++
if (!Checker.isNumberChar(input[index + 1])) {
console.error(
`\x1b[31merror: ${input + "\n" + " ".repeat(index + 7) + "^"}\nInvalid character.\x1b[0m`,
)
throw new Error()
}
while (Checker.isNumberChar(input[index + 1])) index++
}
tokens.push(makeToken(input, TokenKind.NUMBER, start, index - start + 1))
} else if (Checker.isWordChar(token)) {
while (Checker.isWordChar(input[index + 1])) index++

View file

@ -125,7 +125,7 @@ export class Parser {
const operator = this.eat()
const right = this.parsePrimaryExpression()
if (current.value === "%") left = `(${left} - ${left} / ${right} * ${right})`
if (current.value === "%") left = `(${left} - (${left} / ${right} * ${right}))`
else left = `(${left} ${operator.value} ${right})`
}
@ -147,8 +147,12 @@ export class Parser {
return `(${value})`
}
case TokenKind.NUMBER: {
const [num, exp] = (<string>this.eat().value).split("e")
return "" + (exp ? +num * 10 ** +exp : num)
}
case TokenKind.VARIABLE:
case TokenKind.NUMBER:
case TokenKind.STRING:
return <string>this.eat().value