-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.mjs
31 lines (19 loc) · 1009 Bytes
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// https://blog.bitsrc.io/what-is-an-abstract-syntax-tree-7502b71bde27
// 1 * 2 + 3
import BinaryExpression from "./src/BinaryExpression.mjs"
import NumericLiteral from "./src/NumericLiteral.mjs"
import Visitor from "./src/Visitor.mjs"
const visitor = new Visitor()
const oneLiteral = new NumericLiteral(1)
const twoLiteral = new NumericLiteral(2)
const threeLiteral = new NumericLiteral(3)
// console.log("NumericLiteral", oneLiteral.accept(visitor))
const leftExpression = new BinaryExpression(oneLiteral, '*', twoLiteral)
const mainExpression = new BinaryExpression(leftExpression, '+', threeLiteral)
// const binExpression = new BinaryExpression(oneLiteral, '+', twoLiteral)
// const binExpression2 = new BinaryExpression(oneLiteral, '-', twoLiteral)
// console.log("ADD", binExpression.accept(visitor))
// console.log("SUBTRACT", binExpression2.accept(visitor))
// console.log("MULTIPLY", binExpression3.accept(visitor))
console.log(mainExpression)
console.log(mainExpression.accept(visitor))