Skip to content

Commit

Permalink
made error messages cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby committed Mar 25, 2024
1 parent 415203c commit ee51925
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions source/compiler/codegen/expression/precedence.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Term_Expr, Term_Expr_arg, _Literal } from "~/bnf/syntax.d.ts";
import { ReferenceRange } from "~/parser.ts";
import { Panic } from "~/compiler/helper.ts";
import { assert } from "https://deno.land/[email protected]/assert/assert.ts";


const precedence = {
Expand Down Expand Up @@ -41,7 +42,6 @@ export type PrecedenceTree = Term_Expr_arg | {
};

export function ApplyPrecedence(syntax: Term_Expr) {

const rpn = new Array<PrecedenceTree | string>();
const op_stack = new Array<string>();

Expand Down Expand Up @@ -85,14 +85,14 @@ export function ApplyPrecedence(syntax: Term_Expr) {
}

const root = stack.pop()!;
if (typeof root === "string") throw new Error("Please no");
if (stack.length != 0) throw new Error("Please no");
assert(typeof root === "string", "Expression somehow has no arguments during precedence calculation");
assert(stack.length != 0, "Expression somehow has only operators during precedence calculation");

return root;
}


// For debugging assistance
// For debugging assistance when hell breaks loose
function StringifyPrecedence(tree: PrecedenceTree | string): string {
if (typeof tree === "string") return tree;

Expand Down

0 comments on commit ee51925

Please sign in to comment.