diff --git a/compiler/Lexer.ts b/compiler/Lexer.ts index 4067057..fd0f74d 100644 --- a/compiler/Lexer.ts +++ b/compiler/Lexer.ts @@ -51,6 +51,19 @@ export class Lexer { } 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("\"")) { this.step(); let value = ""; diff --git a/compiler/ast.ts b/compiler/ast.ts index f6b9d89..30d46bf 100644 --- a/compiler/ast.ts +++ b/compiler/ast.ts @@ -46,4 +46,13 @@ export type ExprKind = | { type: "null"} | { type: "loop", body: Expr } | { type: "block", stmts: Stmt[], expr?: Expr } - ; \ No newline at end of file + ; + +export type Sym = { + ident: string, + type: "let" | "fn" | "fn_param" | "builtin", + pos?: Pos, + stmt?: Stmt, + param?: Param, +} +