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

Commit 4be5c48

Browse files
committed
Add parsing assignment operators with constants
1 parent f33dfde commit 4be5c48

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/parser.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ function parsePrint(): SyntaxTree {
235235
* 0 1 2 3 4
236236
* a = b + c
237237
*
238+
* 0 1 2
239+
* a = b
240+
*
238241
* 01
239242
* a++
240243
* a--
@@ -306,20 +309,31 @@ function parseExpression(): SyntaxTree {
306309

307310
let operation: Token = getToken(currentIndex + 3)
308311

312+
/* Assign */
309313
if (operation.type != Type.PUNCTUATION) {
310314
adjust = 3
315+
316+
let argument2: SyntaxTree
317+
318+
/* Constant */
319+
if (address1.type == Type.CONSTANT) {
320+
argument2 = createConstant(address1)
321+
/* Identifier */
322+
} else {
323+
argument2 = {
324+
content: VARIABLE,
325+
argument1: { content: address1 },
326+
argument2: { content: type1 }
327+
}
328+
}
311329
expression = {
312330
content: ASSIGN,
313331
argument1: {
314332
content: VARIABLE,
315333
argument1: { content: result },
316334
argument2: { content: type }
317335
},
318-
argument2: {
319-
content: VARIABLE,
320-
argument1: { content: address1 },
321-
argument2: { content: type1 }
322-
}
336+
argument2: argument2
323337
}
324338
} else {
325339
let address2: Token = getToken(currentIndex + 4)

0 commit comments

Comments
 (0)