forked from msasama/Postfix_Prefix_Evaluation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_eval.html
60 lines (52 loc) · 2.24 KB
/
post_eval.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Postfix Evaluation</title>
<link rel="stylesheet" href="style.css">
<script src="post_eval.js"></script>
</head>
<body>
<div class="box">
<h1>Postfix Evaluation</h1>
<div class="inst">Enter your postfix expression in the box below</div>
<div class="input">
<input type="text" placeholder="Enter your expression" id="expression">
<button onclick="evaluatePostfixExpression()">Evaluate</button>
</div>
<div class="result">
<label for="result">RESULT:</label>
<input type="text" id="result" readonly>
</div>
<div class="btns">
<button onclick="alert('Postfix evaluation is currently active')">Postfix</button>
<button onclick="window.location.href='pre_eval.html'">Prefix</button>
</div>
<div class="madeby">
<span>By <a href="https://github.com/souhardyaghosh">Souhardya</a> and <a href="https://github.com/msasama">Shazeb</a></span>
</div>
</div>
<script>
// Wait for the WebAssembly module to be fully initialized
Module.onRuntimeInitialized = function() {
console.log("WebAssembly module loaded.");
var evaluatePostfix = Module.cwrap('evaluate_postfix', 'number', ['string']);
window.evaluatePostfixExpression = function() {
try {
var expression = document.getElementById('expression').value;
if (!expression) {
alert("Please enter a valid expression.");
return;
}
var result = evaluatePostfix(expression);
document.getElementById('result').value = result;
} catch (error) {
console.error("Error evaluating expression:", error);
alert("An error occurred. Check the console for details.");
}
};
};
</script>
</body>
</html>