parser stuff

This commit is contained in:
Mikkel Kongsted 2024-11-22 14:06:28 +01:00
parent c2a5b66318
commit 353d38a5a4
2 changed files with 23 additions and 1 deletions

View File

@ -51,6 +51,19 @@ export class Lexer {
} }
return { ...this.token("int", pos), intValue: parseInt(textValue) }; return { ...this.token("int", pos), intValue: parseInt(textValue) };
} }
if (this.test("0")) {
this.step()
if (!this.done() && this.test(/[0-9]/)) {
console.error(
`Lexer: invalid number`
+ ` at ${pos.line}:${pos.col}`,
);
return this.token("error", pos);
}
return { ...this.token("int", pos), intValue: 0};
}
if (this.test("\"")) { if (this.test("\"")) {
this.step(); this.step();
let value = ""; let value = "";

View File

@ -46,4 +46,13 @@ export type ExprKind =
| { type: "null"} | { type: "null"}
| { type: "loop", body: Expr } | { type: "loop", body: Expr }
| { type: "block", stmts: Stmt[], expr?: Expr } | { type: "block", stmts: Stmt[], expr?: Expr }
; ;
export type Sym = {
ident: string,
type: "let" | "fn" | "fn_param" | "builtin",
pos?: Pos,
stmt?: Stmt,
param?: Param,
}