
EASY41 is a little compiler for the HP41.  (Version 1.0)
--------------------------------------------------------

You need the VFP runtime found at the SIM41W page in my Internet
site:  http://www.geocities.com/algesuar

The VFP runtime could be found at http://www.hp41.org. packed in
a single file.  Go to Emulators: SIM41W


A program could be written using a high level language and compiled
into HP41 code using EASY41.


In order to write a source program use a editor as NOTEPAD or EDIT


Later, translate your program to HP41 code using:


EASY41 xxxx.prg yyyy.prg

where xxxx.prg is your original program
and yyyy.prg is the name for the generated HP41 program.

Also you could use:


EASY41 xxxx.prg xxxx.out



Examples:
---------


EASY41 double.prg dou.prg


EASY41 sum02.prg s2.prg


EASY41 sum01.prg add00.prg


EASY41 fibonacci.prg fibonacci.out


Look at those examples provided with this compiler.



Expressions allowed:
------------------
variable=number

variable=variable

variable=variable+number

variable=variable-number

variable=variable*number

variable=variable/number

variable=variable+variable

variable=variable-variable

variable=variable*variable

variable=variable/variable

Expressions must be surrounded by blanks.
Inner blanks in expressions are not allowed.

Easy41 Version 1.01 translates a expresion to Reverse Polish
Notation, from left to right.

Example:

A=B*C+2/DELTA-5 is translated to:

RCL B
RCL C
*
2
+
RCL DELTA
/
5
-
STO A

Later, the variable names are converted to register
numbers.

Operators allowed in this version: +-*/


Structures:
-----------

IF    variable1=variable2     (variable1=variable2 without inner blanks)
   ....
   ....
ENDIF
IF   variable=number
  ....
  ....
ENDIF
The operator also could be < , >, =, #  (# means not equal)


This structure is an infinite loop:

DO
  ....
  ....
  LOOP   
  ....
  ....
  EXIT
  ....
  ....
ENDDO


LOOP translates flow to the beginning of the current DO
EXIT jumps to the following line after ENDDO in the current DO
  

I/O:
----
Implemented INPUT and PRINT, the Sintax is:

INPUT variable

PRINT variable


Comments:
---------

// this is a comment


Reserved variables X,Y,Z,T .Do not use those names.
New: Version 1.01 . You could use X,Y,Z and T
within expressions. These special variables are 
translated to _X,_Y,_Z,_T

Example:

A=X+Y+M-OMEGA  is converted to:

RCL _X
RCL _Y
+
RCL M
+
RCL OMEGA
-
STO A

Why underscores?. 
Because you could have HP41 commands in your
program such as RCL Y (RCL from memory Y in
the stack)

Mixed HP41 commands and EASY41 commands allowed
in the same program.

Nested IFs and Nested DOs don't implemented yet.

However, it is allowed IFs within DOs - ENDDOs
and DOs structures within IFs - ENDIFs


Expressions are delimited with blanks and in this version inner
blanks are not allowed.


The compiler does the job of translating the source to the
object in 6 steps:

Pass0 and Pass1: (Translate from a free context grammar to a fixed format grammar)
Pass0:  Search for tokens and expressions and isolate them.
Pass1:  If a token has a parameter put the parameter at right of the original token.
Pass2:  Translate DOs, ENDDOs, IFs, ENDIFs, LOOPs, EXITs, INPUTs and PRINTs 
Pass3:  Translate expressions to RCLs and STOs with named registers.
Pass4:  Translate RCLs and STOs with variable names into RCLs and STOs
           with register numbers.
Pass5:  Translate ALPHA GTOs and ALPHA LBLs to GTOs and LBLs with numbers.

You can view the output of each pass.
Look at pass*.txt   .  
pass5.txt is the output program

Compiler output:
-------------------
When compiling the following files are generated:
pass0.txt
pass1.txt
pass2.txt
pass3.txt
pass4.txt
pass5.txt
varnames.txt
gtonames.txt
and the output program.

Note:
The last program compiled was fibonacci.prg. So, if you look at
pass0.txt until pass5.txt, those files were generated for the
fibonacci program. The same apply to varnames.txt and gtonames.txt


You could  watch to these files in order to review the translation process.


The compiler is in Alpha State. Written between june 1 and june 5/2005
The compiler uses a variation of FOCALFREE for pass1.


by Alvaro Gerardo Surez.
http://www.geocities.com/algesuar
