-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
83 lines (67 loc) · 2.26 KB
/
main.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
P# (PSharp Language)
Made in TypeScript, by DONT PAN!C STUDIOS.
*/
const isSeparator = (value: string): boolean => value === '/'|| value === '\\' || value === ':';
const getExtension = (path: string): string => {
for (let i = path.length - 1; i > -1; --i) {
const value = path[i];
if (value === '.') {
if (i > 1) {
if (isSeparator(path[i - 1])) {
return '';
}
return path.substring(i + 1);
}
return '';
}
if (isSeparator(value)) {
return '';
}
}
return '';
};
import Parser from "./src/parser.ts";
import { evalhandle } from "./src/runtime/interpreter.ts";
import { setupGlobalScope } from "./src/runtime/env.ts";
//const startarg = process.argv.slice(2);
initrun('example.ps')
async function initrun(filename: string) {
const ver = 'v1.0.0';
const parser = new Parser();
const env = setupGlobalScope();
console.log("psharp.log: Running P# " + ver + " interpreter.")
if(getExtension(filename) == 'ps') {
const input = await Deno.readTextFile(filename);
if(input.length == 0) {
console.warn('psharp.core: no input file, returning null');
}
const program = parser.produceAST(input);
const result = evalhandle(program, env);
//console.log(result);
} else {
console.error("psharp.core: PSharp Interpreter only supports '.ps' file extension.");
}
}
/*
function repl() {
const parse = new Parser();
const env = setupGlobalScope();
// setup default variables
env.declareVar('psharptestvar', MK_NUM(100), true);
env.declareVar('true', MK_BOOL(true), true);
env.declareVar('null', MK_NULL(), true);
env.declareVar('false', MK_BOOL(false), true);
console.log("P# 1.0.0 (in deno)\nType 'core.exit()' or 'exit' to exit program.");
while(true) { // main function
const input = prompt("> ");
if(!input || input.includes("core.exit()") || input.includes("exit")) {
console.log("Exiting")
Deno.exit(0);
}
const program = parse.produceAST(input);
const result = evalhandle(program, env);
//console.log(result);
}
}
*/