-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
36 lines (30 loc) · 1.31 KB
/
index.js
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
function parse_input() {
let productions_input = document.getElementById('productions_input').value
const word_input = document.getElementById('word_input').value.trim()
// Convert newlines to comma and remove spaces and dots
productions_input = productions_input.trim()
productions_input = productions_input.replace(/ /g, '')
productions_input = productions_input.replace(/\n/g, ',')
productions_input = productions_input.replace(/,+/g, ',')
productions_input = productions_input.replace(/\./g, '')
// Replace html/latex arrows through simple - and >
productions_input = productions_input.replace(/→/g, '->')
// Replace latex short pipe ∣ with long keyboard pipe |
productions_input = productions_input.replace(/∣/g, '|')
const lines = productions_input.split(',')
let productions = []
for (let line of lines) {
// Left of -> is the producer and right are the products
let [producer, products] = line.split('->')
products = new Set(products.split('|'))
productions.push({producer, products})
}
const word = word_input
return {productions, word}
}
function render_cyk() {
const input = parse_input()
const cyk = new CYK(input)
const result = cyk.toString()
document.getElementById("output").innerHTML = result
}