User Tools

Site Tools


xrpl:rpl_language_overview

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
xrpl:rpl_language_overview [2019/05/05 15:05] – Added in-fix nototation via MPLLang translator added stub, changed heading levels Karsten75xrpl:rpl_language_overview [2019/12/02 09:14] Karsten75
Line 8: Line 8:
 When we talk about common aspects of all the languages, it's easiest to write xRPL where the "x" denotes commonality. )) is a stack-based, Reverse Polish Notation language. There, now that we've said it, what does it mean? When we talk about common aspects of all the languages, it's easiest to write xRPL where the "x" denotes commonality. )) is a stack-based, Reverse Polish Notation language. There, now that we've said it, what does it mean?
  
-xRPL 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 xRPL and stack-based programming. <wrap info>For a more detailed CRPL explanation, see the [[crpl:crpltutorial|Tutorial]].</wrap>+xRPL 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 xRPL and stack-based programming. <wrap info>For a more detailed CRPL explanation, see the [[crpl:crpltutorial|CRPL Tutorial]].</wrap>
  
 An xRPL instruction either use arguments (data) that is on a "stack", or place arguments on the "stack". Arguments on the stack are in LIFO (**L**ast **I**n, **F**irst **O**ut) order. That means the argument taht was placed on the stack last will be the first to be retrieved. Imagine this as a stack of coins. If you put a coin on the top, then the first coin to be taken off will also be the one that was last placed on the stack.  An xRPL instruction either use arguments (data) that is on a "stack", or place arguments on the "stack". Arguments on the stack are in LIFO (**L**ast **I**n, **F**irst **O**ut) order. That means the argument taht was placed on the stack last will be the first to be retrieved. Imagine this as a stack of coins. If you put a coin on the top, then the first coin to be taken off will also be the one that was last placed on the stack. 
Line 115: Line 115:
 Both the above statements assign 7 to the variable "x". Choose which format you prefer and you think makes your code most readable - then be consistent. :) Both the above statements assign 7 to the variable "x". Choose which format you prefer and you think makes your code most readable - then be consistent. :)
  
 +==== Symbol Aliasing ====
 +
 +Many arithmetic operators  can be substituted with shorthand symbols **(4RPL only)**. 
 +
 +^ Operator ^ Symbol ^
 +| ADD | + | 
 +| SUB | - | 
 +| MUL | * | 
 +| DIV | / | 
 +| MOD | % | 
 +| AND | && | 
 +| OR  | %%||%% | 
 +| NOT | ! | 
 +| POW | %%^%% | 
 +| GT  | > | 
 +| GTE | >=| 
 +| LT  | < | 
 +| LTE | <= |  
 +| EQ  | == | 
 +| NEQ | != | 
 + 
 ==== Code translator ==== ==== Code translator ====
-[[https://github.com/Arin112}Arin112]]+[[https://github.com/Arin112}Arin112]] wrote a code translator that can translate in-fix ((Infix notation is the notation commonly used in arithmetical and logical formulae and statements. It is characterized by the placement of operators between operands—"infixed operators"—such as the plus sign in 2 + 2.)) code to the xRPL post-fix notation.  
 + 
 +For those struggling to master xRPL's post-fix format, this may be a useful tool. It can be obtained from [[https://github.com/Arin112/mplLang|github]] and is accompanied by many samples. Of course, it should be noted that the code and translation will only be up-to-date as long as the repository is maintained.  
 + 
 +Here are some sample translations, taken directly from the GitHub repository: 
 + 
 +<WRAP group> 
 +<WRAP half column> 
 +**mplLang code** 
 +<code c> 
 +x = 2 + 2 * 2; 
 +</code> 
 +</WRAP> 
 +<WRAP half column> 
 +**xRPL translated code** 
 +<code 4rpl> 
 +2 2 2 mul add ->x 
 +</code> 
 +</WRAP> 
 +</WRAP> 
 + 
 +<WRAP group> 
 +<WRAP half column> 
 +<code c> 
 +z = f(x, y); 
 +</code> 
 +</WRAP> 
 +<WRAP half column> 
 +<code 4rpl> 
 +z = f(x, y); 
 +</code> 
 +</WRAP> 
 +</WRAP> 
 + 
 +<WRAP group> 
 +<WRAP half column> 
 +<code c> 
 +[x, y] = CurrentCoords(); 
 +</code> 
 +</WRAP> 
 +<WRAP half column> 
 +<code 4rpl> 
 +CurrentCoords ->y ->x 
 +</code> 
 +</WRAP> 
 +</WRAP> 
 + 
 +<WRAP group> 
 +<WRAP half column> 
 +<code c> 
 +if(a<b && (c+1 == -c)) [a, b, c] = 1, 2.0, 3.14; 
 +</code> 
 +</WRAP> 
 +<WRAP half column> 
 +<code 4rpl> 
 +<-a <-b lt <-c 1 add <-c neg eq and if 
 +1 2 3.140000 ->c ->b ->a 
 +endif 
 +</code> 
 +</WRAP> 
 +</WRAP> 
 + 
 +<WRAP group> 
 +<WRAP half column> 
 +<code c> 
 +do (1 .. 42){ 
 +a = refRead("num"); 
 +refWrite(7*(3.14+i), "num"); 
 +
 +</code> 
 +</WRAP> 
 +<WRAP half column> 
 +<code 4rpl> 
 +42 1 do 
 +"num" <-! ->a 
 +7 3.140000 i add mul "num" ->! 
 +loop 
 +</code> 
 +</WRAP> 
 +</WRAP>