parser stuff

This commit is contained in:
Mikkel Kongsted 2024-11-21 14:38:33 +01:00
parent af8ce1d47a
commit 6ce48aae2a
3 changed files with 24 additions and 20 deletions

View File

@ -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")) {

View File

@ -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;
}

View File

@ -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);