-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayground.html
More file actions
62 lines (51 loc) · 1.27 KB
/
playground.html
File metadata and controls
62 lines (51 loc) · 1.27 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
body {
font-family: verdana, arial, sans-serif;
font-size: 20px;
background-color: #cccccc;
}
input {
padding: 0;
margin: 0;
font-size: inherit;
}
input[type="button"] {
padding: 2px;;
}
</style>
</head>
<body>
<div>
<label>Enter an expression: <input type="text" id="input"></label>
</div>
<div>
<input type="button" id="evaluate-btn" value="Evaluate">
</div>
<div>
Result: <span id="output"></span>
</div>
<script src="shunting_yard.js"></script>
<script>
var inputField = document.getElementById("input");
var outputElem = document.getElementById("output");
var evaluateBtn = document.getElementById("evaluate-btn");
evaluateBtn.addEventListener("click", function () {
var expr = inputField.value;
var result;
try {
var tokens = Tokenizer.tokenize(expr);
var ast = AST.create(tokens);
result = ast.evaluate();
} catch (ex) {
result = "Error: " + ex.message;
}
outputElem.innerHTML = result;
});
</script>
</body>
</html>