diff --git a/compiler/Parser.ts b/compiler/Parser.ts index 6a37e9b..7d50c6b 100644 --- a/compiler/Parser.ts +++ b/compiler/Parser.ts @@ -91,7 +91,11 @@ export class Parser { if (this.test("}")) { this.step(); return this.expr({ type: "block", stmts }, pos); - } else if (this.test("fn")) { + } else if (this.test("return") || this.test("break") || this.test("let")) { + stmts.push(this.parseSingleLineBlockStmt()); + this.eatSemicolon(); + } + else if (this.test("fn")) { stmts.push(this.parseSingleLineBlockStmt()); stmts.push(this.parseFn()); } else if (this.test("{") || this.test("if") || this.test("loop")) { diff --git a/compiler/example-no-types.slg b/compiler/example-no-types.slg index a9f9b31..019c744 100644 --- a/compiler/example-no-types.slg +++ b/compiler/example-no-types.slg @@ -1,15 +1,15 @@ -fn sum(a, b) { - + a b; -} +//fn sum(a, b) { +// + a b; +//} +// +//add(2,3); // -> 5 +// +//let a = "Hello"; +// +//let b = "world"; -add(2,3); // -> 5 - -let a = "Hello"; - -let b = "world"; - -//println(+ (+ a " ") (+ b "!")); // -> "Hello world!" +println(+ + + a " " b "!"); // -> "Hello world!" if == a b { println("whaaaat"); @@ -19,11 +19,11 @@ else { } loop { -// let i = 0; -// -// if >= i 10 { -// break; -// } -// -// i = i + 1; + let i = 0; + + if >= i 10 { + break; + } + + i = + i 1; } \ No newline at end of file diff --git a/compiler/main.ts b/compiler/main.ts index e140e76..536b495 100644 --- a/compiler/main.ts +++ b/compiler/main.ts @@ -1,8 +1,8 @@ import { Lexer } from "./Lexer.ts"; import { Parser } from "./Parser.ts"; -//const text = await Deno.readTextFile("example-no-types.slg"); -const text = await Deno.readTextFile("example.slg"); +const text = await Deno.readTextFile("example-no-types.slg"); +// const text = await Deno.readTextFile("example.slg"); const lexer = new Lexer(text);