-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjspython
More file actions
executable file
·36 lines (28 loc) · 913 Bytes
/
jspython
File metadata and controls
executable file
·36 lines (28 loc) · 913 Bytes
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
32
33
34
35
36
#!/usr/bin/env node
"use strict"
const fs = require("fs")
const SyntaxAnalyzer = require("./src/syntax-analyze/syntax-analyzer")
const Tokenizer = require("./src/token-analyze/tokenizer")
const Executor = require("./src/execution/executor")
let srcFilePath = process.argv[2]
if (srcFilePath === undefined) {
// code from stdin
srcFilePath = "<stdin>"
const srcCode = fs.readFileSync(0, "utf-8")
interpret(srcCode, srcFilePath)
} else {
if (fs.existsSync(srcFilePath)) {
const srcCode = fs.readFileSync(srcFilePath, "utf-8")
interpret(srcCode, srcFilePath)
} else {
process.stdout.write("file not exists: " + srcFilePath + "\n")
}
}
function interpret(code, fileName) {
const syntaxAnalyzer = new SyntaxAnalyzer(
new Tokenizer(code, fileName).prepare()
)
const programNode = syntaxAnalyzer.parse()
programNode.print()
console.log(new Executor(programNode).exec())
}