An RPN Language

Started by Charles Pegge, September 14, 2007, 09:25:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

#15
In the early days  Java was originally intended for those devices. :)

But yes I think it could run on very small devices - might be useful for robots too. Forth was originally developed for controlling telescopes and was easy to run on small devices with limited memory. Unfortunately it has not really escaped from its low-level legacy.

The strategy for  the R$ project is to cross-breed Forth ideas with C Basic and XML, inheriting a few essential  concepts from each:



Forth provides the stack machine and postfix notation

C provides types, strucures and pointers

Basic provides dynamic strings and string manipulation functions.

XML provides object structure, storage and expression.


These are tightly integrated into a language with a minimalist syntax, (and simple code!)
The main task is to make sure all the bits fit together nicely. For example:




"myprog.prg" load exec  | loads  a program file onto the stack and executes it

"mydata.dat" load  | puts mydata on to the stack

"myfiledat.dat" file 10 seek 40 get | opens a file a extracts a 40 byte section

"myfile.dat" filein (in ... ) close | opens a file reads the first line then closes it.

"myfile.txt" fileout | output literal text
(

$
Hello World !
Hello Sky!
$
)
close


Petr Schreiber

I second Kents idea,

this could be perfect for hand held devices.
Now just to get somebody who can design new calculator HW in "old" HP way :(


Thanks,
Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com
  •  

Charles Pegge

#17
First I need a new soldering iron. though the chips are a lot smaller these days.

But seriously the next generation of calculators will probably run Linux and have 4 gigs of flash memory and built in camera as standard. Not to mention the toaster with wireless internet. So I suspect the opportunities for developing new hardware on the kitchen table are limited.

The low level functions for R$ are gradually coming together, maintaining cross-compatibility with different variable types is quite a challenge - in fact easier to do in assembler than Basic.

High level OOP notation

Coming back to high level notation, this is how an object can be instantiated from a class. The object has a property and its own method which calls its class method.

All the tag names are arbitrary. The '!' denotes a Method. Every thing else including nested tags,
is a Property. When invoked, Properties are loaded onto the stack and Methods are executed.

The '$' is a special kind of quote. So the whole class and the embedded object structure is contained in the quoted string, which is assigned the name 'myclass'.

The comma is a concatenation operator for any string including UDT strucures. It appends the string to the previous string on the stack without affecting the stack pointer.  The '+' operator is not used for concatenating strings any more.

I hope this is not too confusing. Much is done with very little.



$
  <method>!
     2 args  :  person : greeting
     greeting  person ,  '!' ,  ?
  </>
  <object>
    <myproperty> Hello </>
    <mymethod>!
      this.myproperty myclass.method
 
   </mymethod>
  </object>
$

: myclass

myclass.object  :  myobject   |  instantiate myobject

"Petr" myobject.mymethod   | invoke method with 'Petr' as a parameter


| Result: Hello Petr!

PS. This needs the new version since I have tweaked a few things. I will post it very soon.


Petr Schreiber

Hi Charles,

thanks for the update.
That first method ( greetings ) bleongs to which class ?


Bye,
Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com
  •  

Charles Pegge


Person and greeting are parameters for the myclass.method

The 2 args puts the stack pointer back two places, allowing the 2 arguments to be given names and made accessible to the method.

To explain further:

The first parameter was stacked just before myobject.mymethod was invoked.

myibject.mymethod then added  this.myproperty to the stack which contained "hello".

It then invoked myclass.method

Myclass.method then named these two elements and displayed them.

These 2 parameters were then automatically disallocated at the end of the method.



I should also add that the instantiated myobject is simply a subsection of myclass pushed onto the stack, and looks like this:


     <myproperty> Hello </>
    <mymethod>!
      this.myproperty myclass.method

    </mymethod>