Advertisement
BLUSHIF

Untitled

Nov 4th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>PsuedoJS-Convert psuedocode to JS</title>
  5. <script type="text/javascript">
  6. function convert(x){
  7. var ot;
  8. var m=x.split('\n');
  9. for(i=0;i<m.length;i++){
  10. var c=m[i].split(' ');
  11. console.log(c);
  12. for(int h;h<c.length;h++){
  13. if(c[h]=="")h++;
  14. if(c[h]=="end"||c[h+2]=="while"){
  15. c[h]="}";c[h+2]="";
  16. }
  17. if(isNaN(c[h])||c[h+2]=="="){
  18. c[h]="var "+c[h];c[h+4]=c[h+4]+";";
  19. }
  20. if(c[h]=="while"||c[h+2]=="while"){
  21.  
  22. }
  23. }
  24. }
  25. document.getElementById('i').value=ot;
  26. }
  27. </script>
  28. </head>
  29. <body>
  30. <h1>Input:</h1>
  31. <textarea id="i" rows="15"cols="50"></textarea>
  32. <hr>
  33. <button onclick="convert(document.getElementById('i').value);">Convert</button>
  34. <hr>
  35. <h1>Output:</h1>
  36. <textarea id="o" rows="15"cols="50"></textarea>
  37. <hr>
  38. <h1>Help</h1>
  39. <p>What is psuedocode?</p>
  40. <p>Psuedocode is a simple structure of code, meant to model a function</p>
  41. <p>This psuedocode performs a simple insertion sort(Thanks to wikipedia for this sample)</p>
  42. <pre>
  43. i = 1
  44. while i < length(A)
  45. j = i
  46. while j > 0 and A[j-1] > A[j]
  47. swap A[j] and A[j-1]
  48. j = j - 1
  49. end while
  50. i = i + 1
  51. end while
  52. </pre>
  53. <h1>WARNING:please format all psuedocode like this example, with space seperation and single-letter variables.</h1>
  54. </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement