-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
52 lines (49 loc) · 1.7 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
/>
<title>weval: the wasm evaluator</title>
<style>
body, html{
height: 100vh;
}
body{
display: flex;
justify-content: center;
align-items: center;
padding: 2rem;
}
</style>
</head>
<body>
<main class="container-fluid">
<form>
<input type="text" id="input" placeholder="insert a mathematical expression" />
<h6 id="output">-</h6>
<input type="button" id="evalbtn" value="Evaluate"></input>
</form>
</main>
<script type="module">
import init, { eval_float64, tokenizer, infix_to_postfix_tokens } from './pkg-web/weval.js';
await init();
// add event listener to button
document.getElementById('evalbtn').addEventListener('click', () => {
// get input value
const input = document.getElementById('input').value;
// evaluate input
const output = eval_float64(input);
// display output
document.getElementById('output').innerText = output;
let tokens = tokenizer(input);
//execute the shunting yard algorithm on the tokens
let postfixTokens = infix_to_postfix_tokens(tokens)
console.log('look mum, i made a postfix expression: ')
console.log(postfixTokens.join(' '))
});
</script>
</body>
</html>