Advertisement
Guest User

sophie.salm

a guest
Feb 4th, 2012
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. /* file "sophie.salm" */
  2.  
  3. /*
  4. * This file contains a Salmon interactive interpreter (a REPL).
  5. * Run with: `salmoneye sophie.salm`
  6. * Or with the optimized interpreter: `salmoneye.fast sophie.salm`
  7. * Written by Tommy Ettinger, named after his dog.
  8. */
  9.  
  10. /*
  11. This is free and unencumbered software released into the public domain.
  12.  
  13. Anyone is free to copy, modify, publish, use, compile, sell, or
  14. distribute this software, either in source code form or as a compiled
  15. binary, for any purpose, commercial or non-commercial, and by any
  16. means.
  17.  
  18. In jurisdictions that recognize copyright laws, the author or authors
  19. of this software dedicate any and all copyright interest in the
  20. software to the public domain. We make this dedication for the benefit
  21. of the public at large and to the detriment of our heirs and
  22. successors. We intend this dedication to be an overt act of
  23. relinquishment in perpetuity of all present and future rights to this
  24. software under copyright law.
  25.  
  26. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  29. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  30. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  31. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  32. OTHER DEALINGS IN THE SOFTWARE.
  33.  
  34. For more information, please refer to <http://unlicense.org/>
  35. */
  36. use "parse.salm" : "parse.si";
  37.  
  38. print("Welcome to Sophie, an interactive mode for Salmon.\nPress Ctrl-C to quit.\n");
  39. variable ln := "";
  40. variable src := "";
  41.  
  42. variable mute := "variable __dum := (variable := \"\" ); variable __out := standard_output; \n standard_output := open_output_string(__dum);\n";
  43. variable unmute := " standard_output := __out; \n";
  44.  
  45. while(ln != end_of_input)
  46. {
  47. print("> ");
  48. ln ~= read_line();
  49.  
  50. try
  51. {
  52. variable sb := parse_statement_block(mute ~ src ~ unmute ~ ln);
  53. sb.bind_standard_library();
  54. sb.run();
  55. src ~= ln;
  56. }
  57. catch
  58. {
  59. if (current_exceptions()[0].tag == et_parse_syntax_error)
  60. {
  61. try
  62. {
  63. variable px := parse_expression(ln);
  64. px.bind_standard_library();
  65. px.run()!
  66. ln := "";
  67. goto continue;
  68. }
  69. catch
  70. {
  71. if (current_exceptions()[0].tag == et_parse_more)
  72. {
  73. try
  74. {
  75. variable psb := parse_statement_block("variable o_o := " ~ ln ~ "\no_o!");
  76. psb.bind_standard_library();
  77. psb.run();
  78. ln := "";
  79. goto continue;
  80. }
  81. catch
  82. {
  83. //current_exceptions()[0].message!
  84. };
  85. };
  86. print(">");
  87. goto continue;
  88. };
  89. };
  90. current_exceptions()[0].message!
  91. };
  92. ln := "";
  93. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement