This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
prpl:overview [2016/09/19 03:18] – [Creating PRPL Scripts] GoodMorning | prpl:overview [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | < | ||
- | < | ||
- | |||
- | |||
- | ===== PRPL - The Language ===== | ||
- | PRPL (**< | ||
- | |||
- | PRPL programming is similar to programming a HP calculator or Forth language programming. If this is not something you have done, read on for a brief introduction to PRPL and stack-based programming. < | ||
- | |||
- | Each PRPL instruction (term) uses one or more arguments that are on a " | ||
- | |||
- | You can place arguments on the stack by typing them, or executing an instruction that will push arguments on to the stack. For instance, you can type < | ||
- | |||
- | As an illustration, | ||
- | *< | ||
- | *< | ||
- | add</ | ||
- | |||
- | | ||
- | Both will read the two most recent arguments on the stack (4 and 5), add them and push the sum on to the stack. After the instruction has completed, there will be two numbers on the stack. The " | ||
- | < | ||
- | |||
- | < | ||
- | You can find more commands and detailed explanations of them in the [[PRPL: | ||
- | </ | ||
- | |||
- | ==== Comments ==== | ||
- | |||
- | Adding comments makes code easier to understand, and sometimes helps the programmer or another reader to grasp complex pieces of logic. Also, after some time interval, it refreshes one's memory about exactly what a certain piece of code was intended to do. | ||
- | |||
- | Comments in PRPL can be either a whole line or a partial line. The comment terminates when a line ends. | ||
- | |||
- | Comments are indicated by the " | ||
- | |||
- | |||
- | < | ||
- | # that are on the stack | ||
- | # Below is code # | ||
- | 2 4 5 add # adds 4 and 5 to get 9</ | ||
- | |||
- | ==== Stack Notation ==== | ||
- | |||
- | Every PRPL operand takes zero or more arguments from a " | ||
- | |||
- | * The term is defined by two dashes: %% -- %% | ||
- | * Preceding the term are the arguments consumed from the stack. | ||
- | * Following the term are the arguments pushed onto the stack. | ||
- | For instance, the instruction to add two numbers are: | ||
- | |||
- | < | ||
- | |||
- | Stack notation to represent this will be: | ||
- | |||
- | < | ||
- | In general, if we do not know the exact values of the arguments, an indicator of the argument would be given. Thus if we know the add command takes two input arguments and produces one output argument, then we notate it like this | ||
- | < | ||
- | |||
- | |||
- | **Note:** Unless explicitly noted otherwise, all instructions are destructive stack operations in that they will remove as many arguments as is required for their execution from the stack and replace those with the output from their execution. In the example above, the original two items on the stack have been replaced by their sum. | ||
- | |||
- | Likewise, note that the most recent item pushed on to the stack will also be the first item to be removed. This is referred to as LIFO (**L**ast **I**n, **F**irst **O**ut) processing. | ||
- | |||
- | The following convention is followed to represent items on the stack notation | ||
- | |||
- | |< 80% 15% >| | ||
- | |b |**Boolean** ; nominally a 1 or a zero, representing True or False| | ||
- | |i |**Integer** ; an integer. The PRPL run-time will, if possible, convert the argumant to an integer.| | ||
- | |n |**Term** ; a generic argument. Any term that will be accepted by the instruction. If possible, the PRPL run-time will attempt conversion between types.| | ||
- | |f |**Float** ; a floating point value. If possible, the PRPL run-time will attempt conversion between types.| | ||
- | |x, y |**Coordinate** ; an integer that represents a valid X- or Y-coordinate on the map.| | ||
- | |L |**List** ; a list is capable of storing multiple values in an orderly system.| | ||
- | |s |**String** ; a string of one or more text characters. If possible, numeric values will be converted at run-time.| | ||
- | |||
- | ==== Warp Notation ==== | ||
- | |||
- | An extra and optional operator to PRPL allows for a reversed order that you write some things in PRPL. It doesn' | ||
- | |||
- | This operator is the " | ||
- | |||
- | < | ||
- | |||
- | This means to push 3 to the stack, push 4 to the stack, then to call " | ||
- | < | ||
- | This means two items on the stack before the operation, and one item on the stack afterwards. | ||
- | This is all PRPL (or RPL, or forth...) standard stuff and the primary principle of the language. | ||
- | |||
- | Take a second example: FIXME (Example from CRPL, but the logic is the same) | ||
- | |||
- | < | ||
- | CurrentCoords GetCreeper 1 gt if | ||
- | " | ||
- | endif | ||
- | </ | ||
- | |||
- | This looks at the current coordinates, | ||
- | |||
- | Again, PRPL 101. | ||
- | |||
- | Now, introducing the Warp operator. | ||
- | |||
- | < | ||
- | can become | ||
- | < | ||
- | |||
- | The open parenthesis " | ||
- | |||
- | This also means the same thing: | ||
- | < | ||
- | Here, the " | ||
- | |||
- | Take the second example. | ||
- | < | ||
- | if ( GetCreeper(CurrentCoords) | ||
- | Trace (" | ||
- | endif | ||
- | </ | ||
- | Notice that spaces before or after a warp operator ( which are parentheses) don't matter. | ||
- | |||
- | Note also that this syntax is totally optional and can be intermixed with standard RPL notation as seems appropriate. | ||
- | < | ||
- | 7 -> | ||
- | This means to assign 7 to the variable " | ||
- | So does this: | ||
- | < | ||
- | |||
- | Like any language, you can write some really obfuscated code if you try ([[http:// | ||
- | |||
- | For instance take this clean piece of code: FIXME (CRPL) | ||
- | < | ||
- | CurrentCoords GetCreeper 1 gt if | ||
- | | ||
- | endif | ||
- | </ | ||
- | |||
- | Here it is in bizarro form: | ||
- | < | ||
- | endif(SetCreeper(-10(CurrentCoords(if(gt(1(GetCreeper(CurrentCoords))))))))</ | ||
- | |||
- | |||
- | Here's the same code with just one oddball warp: | ||
- | < | ||
- | endif ( if (GetCreeper(CurrentCoords) gt (1)) | ||
- | SetCreeper(CurrentCoords -10) | ||
- | ) | ||
- | </ | ||
- | |||
- | ==== Typographical conventions ==== | ||
- | **Note:** FIXME This has not yet been implemented. We intend to, but until then the following is merely a placeholder. | ||
- | |||
- | The following typographical conventions are used in this reference document: | ||
- | |< 80% 15% >| | ||
- | |Normal text |Used in most instances.| | ||
- | |Instruction |Refers to a PRPL language element or instruction.| | ||
- | |Argument |Refers to a an argument required for a PRPL instruction.| | ||
- | |User | ||
- | |||
- | ==== Creating PRPL Scripts ==== | ||
- | |||
- | Any text editor can be used to edit PRPL files. However, syntax highlight and auto completion support files will likely soon be provided for the freely available Notepad++ editor. Notepad++ can be obtained from here: | ||
- | [[http:// | ||
- | |||
- | * Once Notepad++ is installed you can add syntax hightlight for the PRPL langage by downloading this file: [[PRPL: | ||
- | * Open Notepad++, | ||
- | *You can add keyword auto completion to Notepad++ by download this file [[PRPL.xml]] | ||
- | * To install into Notepad++ you need to copy PRPL.xml to your Notepad++ install directory\plugins\APIs directory. Then, restart Notepad++. Next, go to the Settings/ | ||
- | \\ | ||
- | \\ | ||
- | \\ | ||
- | FIXME / DELETEME | ||
- | =====Syntax Highlighting in the Wiki ===== | ||
- | |||
- | Dokuwiki uses [[http:// |