-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.html
145 lines (130 loc) · 4.3 KB
/
entry.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<!-- HTML5 Hello world by kirupa - http://www.kirupa.com/html5/getting_your_feet_wet_html5_pg1.htm -->
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Hello...</title>
<style type="text/css">
#mainContent {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
background-color: #E3F0FB;
border-radius: 4px;
padding: 10px;
text-align: center;
}
.status {
font-family: monospace;
}
.buttonStyle {
border-radius: 4px;
border: thin solid #F0E020;
padding: 5px;
background-color: #F8F094;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
font-weight: bold;
color: #663300;
min-width: 75px;
}
.buttonStyle:hover {
border: thin solid #FFCC00;
background-color: #FCF9D6;
color: #996633;
cursor: pointer;
}
.buttonStyle:active {
border: thin solid #99CC00;
background-color: #F5FFD2;
color: #669900;
cursor: pointer;
}
</style>
<script src="Ggg.js"></script>
</head>
<body>
<div id="mainContent">
<div><button id="sampleHelloWorld" class="buttonStyle">Use sample (hello world)</button></div>
<div><button id="compileButton" class="buttonStyle">Compile</button></div>
<p id="comment" class="status">Compilation status goes here.</p>
<p>Add Ggg code here:</p>
<textarea id="GggSource" cols="50" rows="10"></textarea>
<p>Click "Compile", and javacript will emerge here:</p>
<textarea id="JsSource" cols="50" rows="10"></textarea>
<p>If you are not afraid, click</p>
<div><button id="runButton" class="buttonStyle">Run</button></div>
<p>Input your stuff here (it will read q's if empty)</p>
<textarea id="input" cols="50" rows="3"></textarea>
<p>And output goes here:</p>
<textarea id="output" cols="50" rows="10"></textarea>
</div>
<script>
var HelloWorldCode =
"G G G G G G G G G G" + "\n" +
"gg" + "\n" +
"gG G G G G G G G" + "\n" +
"gG G G G G G G G G G G" + "\n" +
"gG G G G" + "\n" +
"gG G" + "\n" +
"Gg Gg Gg Gg g" + "\n" +
"GG" + "\n" +
"\n" +
"gG G G GGG" + "\n" +
"gG G GGG" + "\n" +
"G G G G G G G GGG" + "\n" +
"GGG" + "\n" +
"G G G GGG" + "\n" +
"gG G G GGG" + "\n" +
"Gg Gg G G G G G G G G G G G G G G G GGG" + "\n" +
"gG GGG" + "\n" +
"G G G GGG" + "\n" +
"g g g g g g GGG" + "\n" +
"g g g g g g g g GGG" + "\n" +
"gG G GGG" + "\n" +
"gG GGG" + "\n";
document.getElementById("compileButton").addEventListener('click', compileGgg, false);
document.getElementById("runButton").addEventListener('click', runJavascript, false);
document.getElementById("sampleHelloWorld").addEventListener('click', setHelloWorld, false);
// Put sample Ggg code in Ggg source place
function setHelloWorld() {
document.getElementById("GggSource").value = HelloWorldCode;
}
// Compile Ggg to javascript
function compileGgg() {
var code = document.getElementById("GggSource").value;
var interpreter = new window.Ggg.Interpreter();
var result = interpreter.Interpret(code);
if (result.ok) {
document.getElementById("JsSource").value = result.js;
document.getElementById("comment").textContent = "It's ok";
} else {
document.getElementById("comment").textContent = result.error;
}
}
// Run compiled Ggg code
function runJavascript() {
var jsCode = document.getElementById("JsSource").value;
var input = document.getElementById("input");
var output = document.getElementById("output");
// Read one input character
function read() {
if (input.value.length > 0) {
var char = input.value.charCodeAt(0);
input.value = input.value.substring(1);
return char;
} else {
// if empty, read "q"
return "q".charCodeAt(0);
}
}
// Write character to output
function write(charCode) {
output.value += String.fromCharCode(charCode);
}
//Run the thing
var interpreter = new window.Ggg.Interpreter();
interpreter.RegisterIO(read, write);
interpreter.Run(jsCode);
}
</script>
</body>
</html>