README 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. The ORK (Objekts R Kool) language is insanely verbose but not actually very useful. It's object
  2. oriented beyond all possible usefulness, and makes writing even the most trivial programs long
  3. and complex. Its divine purpose in existance is to be the polar opposite of BrainFuck.
  4. So let's begin!
  5. Please note that this introduction is really only intended for people who already know C++ or
  6. maybe Java, but, to say the least, are comfortable with object-oriented programming. A little bit
  7. of masochism doesn't hurt either.
  8. What people who write C++ would know as the main function is started with the line:
  9. When this program starts:
  10. All functions are instantiated this way. There's a "When" line, then the "code," then a blank
  11. lineto end the function. Here's an example (you can ignore the code, just pay attention to the
  12. "When" lines):
  13. -----
  14. When this program starts:
  15. I have a dog called Bob.
  16. Bob is to bark.
  17. When a dog is to bark:
  18. My voicebox is to say "Woof!\n"
  19. -----
  20. This translates to something like:
  21. -----
  22. int main() {
  23. dog Bob;
  24. Bob.bark();
  25. }
  26. void dog::bark() {
  27. cout << "Woof!\n";
  28. }
  29. -----
  30. Within a function, you can instantiate objects and run objects' functions. There is no
  31. functionality beyond that - all operations must be done through objects.
  32. To instantiate an object, use a line like either:
  33. I have a[n] {object} called {name}.
  34. or
  35. There is a[n] {object} called {name}.
  36. >From then on in that function, that object can be referred to by its name.
  37. For example:
  38. I have a dog called Bob.
  39. or
  40. There is a scribe called Will.
  41. To call a function from an object, use
  42. {object} is to {function} [{parameter}].
  43. Here's an example of that, and an introduction to the built-in scribe object.
  44. -----
  45. When this program starts:
  46. There is a scribe called Will.
  47. Will is to write "Hello World!\n"
  48. -----
  49. This would simply output "Hello World!"
  50. You can also reference variables within an object, such as:
  51. Fibonacci's first operand
  52. That would be equivalant to "Fibonacci.first_operand" in C++. You can set a variable (whether
  53. within an object or not) by:
  54. {variable} is {variable|value}
  55. For example:
  56. Fibonacci's first operand is 1.
  57. So now you ought to be able to write a very simple program. However, you can't do anything very
  58. complex without classes, since ORK is, after all, mindlessly object oriented.
  59. To declare a class, use the line:
  60. There is such a thing as a[n] {name}.
  61. Between that line and the next blank line, you put all the class' functions, etc.
  62. To declare a function within a class:
  63. A {class} can {function} [a[n] {parameter type}].
  64. For example:
  65. -----
  66. There is such a thing as a scribe.
  67. A scribe can write a phrase.
  68. -----
  69. To declare a class variable:
  70. A {class} has [a[n]] {variable name} which is a {variable type}.
  71. For example:
  72. -----
  73. There is such a thing as a mathematician.
  74. A mathematician has a first operand which is a number.
  75. -----
  76. Other than objects, there are only two variable types:
  77. 1) number. This translates to "double," so 1, 2, 3.5, -15, etc.
  78. 2) word, phrase or sentence. All of these translate to "string."
  79. To instantiate a class' function, use:
  80. When a {class} is to {function} [a[n] {variable type}]:
  81. You can then refer to the argument variable by:
  82. the {variable type}
  83. For example:
  84. -----
  85. When a man is to speak a phrase:
  86. There is a scribe called Will.
  87. Will is to write the phrase.
  88. -----
  89. You should now know the entire syntax of the language. So, now it's time for built-in classes.
  90. Firstly, you need to learn the scribe class. This one is so easy, I'll just give an example:
  91. -----
  92. There is a scribe called Will.
  93. I have a phrase called Hamlet.
  94. Hamlet is "To be, or not to be?\n"
  95. Will is to write Hamlet.
  96. -----
  97. The scribe class only has the "write" function, and the "asciiWrite" function. The asciiWrite
  98. function outputs a character from its ASCII value (a number).
  99. Now let's go on to the mathematician class. Because you don't have mathematical operators like +
  100. or -, you have to give the values to a mathematician and have him do the calculations for you. So,
  101. if you wanted to add 5 and 5 and write the result:
  102. -----
  103. There is a scribe called Will.
  104. There is a mathematician called Fibonacci.
  105. Fibonacci's first operand is 5.
  106. Fibonacci's second operand is 5.
  107. Fibonacci is to add.
  108. Will is to write Fibonacci's result.
  109. -----
  110. The mathematician class also has subtract, multiply, divide, modulo and compare. The compare
  111. function will be explored later.
  112. To receive input, there is a class called "inputter." Inputter can:
  113. read a phrase.
  114. read a number.
  115. readOne a phrase.
  116. readOne a number.
  117. say it's done.
  118. The read functions read a word into a string. The read a number version translates that string
  119. into a number. The readOne functions read a single character. The readOne a number version puts
  120. the ASCII value into the number. It says it's done when it receives EOF.
  121. The linguist class is the string variant of the mathematician class. It has a first and second
  122. operand, a result, and two functions:
  123. concatenate.
  124. compare.
  125. The concatenate functions concatenates the first and second operand into the result. The compare
  126. function compares the values of the operands and says it's equal if they're equal, and says it's
  127. not equal if they're not equal.
  128. Sorry, I still haven't covered arrays! Read libork.h ;)
  129. Now, the final bit - program logic.
  130. To compare two numbers, use a mathematician and ask him to compare. For example:
  131. -----
  132. There is a scribe called Will.
  133. There is a mathematician called Fibonacci.
  134. Fibonacci's first operand is 5.
  135. Fibonacci's second operand is 5.
  136. Fibonacci is to compare.
  137. If Fibonacci says it's less then Will is to write "Less!\n"
  138. If Fibonacci says it's equal then Will is to write "Equal!\n"
  139. If Fibonacci says it's greater then Will is to write "Greater!\n"
  140. -----
  141. Naturally, this would output "Equal!"
  142. Loops are a bit more complex. Only an entire function can loop, so generally you want to create a
  143. loop by:
  144. 1) Creating the function you want to loop
  145. 2) Calling it with "If {condition} then I am to {function}"
  146. 3) Looping at the end with the same condition.
  147. When you write "I am to loop," the current function loops, with the same parameters, in the same
  148. class, etc.
  149. So, for example:
  150. -----
  151. When looper is to loop a number:
  152. There is a mathematician called Fibonacci.
  153. I have a number called current.
  154. Fibonacci's first operand is the number.
  155. Fibonacci's second operand is 1.
  156. Fibonacci is to subtract.
  157. current is Fibonacci's result.
  158. Fibonacci's first operand is Fibonacci's result.
  159. Fibonacci's second operand is 0.
  160. Fibonacci is to compare.
  161. If Fibonacci says it's greater then I am to loop.
  162. -----
  163. This would loop from the value you gave it down to 0. You would of course want to add some sort of
  164. functionality there, too.
  165. ORK has a minimal level of pointer support. To put a pointer to an object in a class, use the line
  166. A {class} can have [a[n]] {variable} which is a {type}.
  167. for example:
  168. A linear linked list can have a next which is a linear linked list.
  169. This pointer can be instantiated simply by setting it:
  170. My next is b's next.
  171. or by instanciating it by one of several means:
  172. I have a next which is a linear linked list.
  173. b has a next which is a linear linked list.
  174. b's next's next's next's next's next has a next which is a linear linked list.
  175. And now, on the ORK compiler itself:
  176. Use
  177. ork {program}
  178. to compile a program. C++ code will be outputted to stdout, so
  179. ork {program} > out.cc
  180. will give you a proper C++ file.
  181. To compile the C++ file, you need a line similar to this one:
  182. g++ out.cc -I/opt/ork /opt/ork/libork.a
  183. Where /opt/ork is your ORK directory.