-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic.html
126 lines (101 loc) · 2.74 KB
/
basic.html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<title>BASIC</title>
<style type="text/css" media="screen">
#editor {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width:500px;
font-size:16px;
font-family:monospace
}
#out {
position: absolute;
top: 0;
bottom: 0;
left: 500px;
width:500px
}
aside {
position: absolute;
top: 0;
bottom: 0;
left: 1030px;
width:200px
}
</style>
</head>
<body>
<div id="editor">
a$="AH"
print a$+"OJ"
print fn(factorial,rnd())
factorial: take fact
if fact=1 then return 1
push fact
temp = fn(factorial,fact-1)
pop fact
return temp*fact
</div>
<!--
<textarea id="source" cols=60 rows=40>
dim b(10)
let a=[b(3)]
</textarea>
-->
<textarea id="out" cols=60 rows=40></textarea>
<aside>
<button onclick="compile()">Compile</button>
<br>
<select id="model">
<option value="OMENALPHA" selected>OMEN Alpha</option>
<option value="OMENCHARLIE">OMEN Charlie</option>
</select>
<p><a href="https://github.com/maly/bas80/blob/master/README.md">README, manual etc.</a></p>
</aside>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/ace.js"></script>
<!--script src="./contribution/mode-basic.js"></script-->
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/vbscript");
</script>
<script src="./targets/cpu/8080/library.js"></script>
<script src="./targets/cpu/8080/basic.js"></script>
<script src="./targets/omenalpha/cfg.js"></script>
<script src="./targets/omencharlie/cfg.js"></script>
<script src="lex.js"></script>
<script src="parsing.js"></script>
<script src="generator.js"></script>
<script>
var compile = function(){
var source
//= document.getElementById("source").value
source = editor.getValue()
source=source.replace(/\>\;/gs,">")
source=source.replace(/\<\;/gs,"<")
//source +="\nEND\n"
//var ENGINE = "OMENALPHA"
//var ENGINE = "OMENCHARLIE"
var ENGINE = document.getElementById("model").value;
try{
var basic = parse(source)
console.log(basic)
var asm = generator(basic,CONFIG[ENGINE],BASIC[CONFIG[ENGINE].cpu])
document.getElementById("out").value = (asm)}
catch (e) {
console.log(e)
var err = JSON.parse(e.message)
//console.log(err)
if (source) {
document.getElementById("out").value = "*** ERROR: "+err.error+"\nAt line "+err._numline+"\nCommand "+err._cmd+"\n\n"+err.source
} else {
document.getElementById("out").value = "*** PARSER ERROR: "+err.error+"\nAt line "+err._numline+"\nPosition "+err._cmd
}
}
}
compile()
</script>