-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
42 lines (27 loc) · 1.04 KB
/
script.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
37
38
39
40
41
42
function friday2verilog()
{
var input = document.getElementById("input").value;
// remove spaces before ";""
input = input.replace(/ ;/g, ";");
// remove spaces around "="
input = input.replace(/ = /g, "=");
// add "~" before any negated expression
input = input.replace(/\w*'/g, "~$&");
// remove "'"
input = input.replace(/'/g, "");
// add "[]" around numbers for array indexing
input = input.replace(/\d/g, "[$&]");
// remove duplicate whitespace
input = input.replace(/ +/g, " ");
// replace "+" with verilog OR operator and parentheses
input = input.replace(/ \+ /g, ")|(");
// add AND operator where there is whitespace
input = input.replace(/ /g, " & ");
// add space around OR operator
input = input.replace(/\|/g, " | ");
// add spacing around "=" and first opening parentheses
input = input.replace(/=/g, " = (");
// add last closing parentheses before ";"
input = input.replace(/;/g, ");");
document.getElementById("output").value = input;
};