sharing programmer-to-programmer. please enjoy. pages are formatted for landscape tablet, laptop, or monitor.

yRPN, reverse-polish notation

in production

greek, terpsikhore-seirenes (delight in dance)

yRPN is a little library to convert complicated everyday infix formulas into fast executing reverse-polish notation (rpn) formulas. this is for use with any program, but especially gyges (spreadsheet) and hephaestus (compiler).

was this necessary? absolutely not. but, i needed to be able to expand easily and experiment. plus, while i like public libraries, i don’t really learn when i use them to jump to the end-point. turned out, yrpn helped broaden gyges.

processing into reverse-polish notation is really just a shunting algorithm. it’s not wildly hard. but, controlling when things reappear is the interesting bit.

to the left is a infix equation pulled into tokens. pretty is the version for display. normal is rpn. detailed shows the types — v=variable, o=operator, F=floating point literal.

parsing function is really not harder, it basically an assumption that a variable that appears before an opening parenthesis might be a function. until proven otherwise :)

the detailed line shows “testing” as a f=function and the first parameter as an I=integer literal.

below is a variable definition, t=type, C=character literal

above is a simple c language line, k=keyword

several tables control the final outcome. to the left is the symbol table which identifies association/direction and arity. it also groups by precedence, which is more to the point. finally, this table controls how i “pretty” up formulas after editing and passing the string back.

given my expanded 256 character ascii font, shrike, i also have many additional symbols to help me avoid clumsy function use. for example…

  • power of 2, 3, and 4 are superscripts that attach left

  • square root that groups like the powers above

  • x, y powers that raise to another variable

  • string concatenation operators

  • nand, nor, xor, and nxor symbols

  • ability to expand at will

additionally, yRPN parses full spreadsheet and c source code lines, so it handles functions, variable definitions, cell addresses, etc. i never thought of this use before, but it became a useful addition.

finally, yRPN, helps dissect address references from source applications, like gyges, so it can adjust formulas for cell movements, relative and absolute.

note: in the case of gyges, the spreadsheet, yRPN supports the yCALC library which handles all calculation, dependencies, and sequencing internally. yCALC also takes the final rpn formula and creates byte-code representation for very rapid calculation.

source code is GPL3 licensed, https://github.com/heatherlyrobert/yRPN

Previous
Previous

detailed function statistics with polymnia-hymnos (prd)

Next
Next

eterm color configuration with theia-euryphaessa