Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>PsuedoJS-Convert psuedocode to JS</title>
- <script type="text/javascript">
- function convert(x){
- var ot;
- var m=x.split('\n');
- for(i=0;i<m.length;i++){
- var c=m[i].split(' ');
- console.log(c);
- for(int h;h<c.length;h++){
- if(c[h]=="")h++;
- if(c[h]=="end"||c[h+2]=="while"){
- c[h]="}";c[h+2]="";
- }
- if(isNaN(c[h])||c[h+2]=="="){
- c[h]="var "+c[h];c[h+4]=c[h+4]+";";
- }
- if(c[h]=="while"||c[h+2]=="while"){
- }
- }
- }
- document.getElementById('i').value=ot;
- }
- </script>
- </head>
- <body>
- <h1>Input:</h1>
- <textarea id="i" rows="15"cols="50"></textarea>
- <hr>
- <button onclick="convert(document.getElementById('i').value);">Convert</button>
- <hr>
- <h1>Output:</h1>
- <textarea id="o" rows="15"cols="50"></textarea>
- <hr>
- <h1>Help</h1>
- <p>What is psuedocode?</p>
- <p>Psuedocode is a simple structure of code, meant to model a function</p>
- <p>This psuedocode performs a simple insertion sort(Thanks to wikipedia for this sample)</p>
- <pre>
- i = 1
- while i < length(A)
- j = i
- while j > 0 and A[j-1] > A[j]
- swap A[j] and A[j-1]
- j = j - 1
- end while
- i = i + 1
- end while
- </pre>
- <h1>WARNING:please format all psuedocode like this example, with space seperation and single-letter variables.</h1>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement