Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit c5d3422

Browse files
committed
Check if variables are declared in expressions
1 parent 4d9d122 commit c5d3422

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/parser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ function parseExpression(): SyntaxTree {
313313
let address1: Token = getToken(currentIndex + 2)
314314
let type1: Token = getType(address1, root)
315315

316+
if (type1 == null) {
317+
throw `${address1.lexeme} not declared at ${getLocation(address1)}.`
318+
}
319+
316320
let operation: Token = getToken(currentIndex + 3)
317321

318322
/* Assign */
@@ -345,6 +349,10 @@ function parseExpression(): SyntaxTree {
345349
let address2: Token = getToken(currentIndex + 4)
346350
let type2: Token = getType(address2, root)
347351

352+
if (type2 == null) {
353+
throw `${address2.lexeme} not declared at ${getLocation(address2)}.`
354+
}
355+
348356
if (type.name != "NUMBER") {
349357
throw `${result.lexeme} is not of number type.`
350358
}

0 commit comments

Comments
 (0)