oberonjs.html 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <p>
  5. Oberon module:
  6. </p>
  7. <textarea id="source" rows="10" cols="80">
  8. MODULE test;
  9. IMPORT JS;
  10. BEGIN
  11. JS.alert("Hello, World!")
  12. END test.
  13. </textarea>
  14. <p>
  15. <button onclick="compile()">Compile</button>
  16. <button onclick="compile(); run()">Compile &amp; Run</button>
  17. </p>
  18. <p id="errors" style="color:red">
  19. </p>
  20. <textarea id="result" rows="10" cols="80">
  21. </textarea>
  22. <p>
  23. <button onclick="run()">Run</button>
  24. </p>
  25. <script>
  26. function require(){}
  27. </script>
  28. <script src="oc.js"></script>
  29. <script>
  30. function compile(){
  31. var src = document.getElementById("source").value;
  32. var result;
  33. var errors = "";
  34. try {
  35. result = require("oc.js").compile(src, function(e){
  36. errors += e;
  37. });
  38. }
  39. catch (e) {
  40. errors += e;
  41. }
  42. if (!result)
  43. result = "";
  44. document.getElementById("result").value = result;
  45. document.getElementById("errors").textContent = errors;
  46. }
  47. function run(){
  48. eval(document.getElementById("result").value);
  49. }
  50. </script>
  51. </body>
  52. </html>