Results 1 to 1 of 1

Thread: Possible use of Tokenizer module for emitting calculator instructions

  1. #1
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Cool Possible use of Tokenizer module for emitting calculator instructions

    I recently got into situation I wanted to write some code on my calculator, the problem is it does not support FOR/NEXT, only labels and jumps (it is very low level).
    As the problem required 3 nested loops, this gets quite ugly to maintain.

    The solution to this problem was to use power of ThinBASIC Tokenizer module, and automate the generation of FOR/NEXT equivalent code.
    So as the input goes this:
    FOR I = 1 TO 5
      FOR J = 1 TO 10
        FOR K = 1 TO 15
                               
        NEXT K
      NEXT J
    NEXT I
    
    And the produced output is the following calculator program template (LBL = label, GTO = jump to label, STO = store value from stack to variable, RCL = get value from variable to stack, X<=Y? = compare stack values for X and Y register, and if the condition is valid perform next line, otherwise skip next line):
    LBL 00
    1
    STO I
    LBL 01
      RCL I
      5
      X<=Y?
      GTO 02
      <Place FOR/NEXT body code here>
      LBL 03
      1
      STO J
      LBL 04
        RCL J
        10
        X<=Y?
        GTO 05
        <Place FOR/NEXT body code here>
        LBL 06
        1
        STO K
        LBL 07
          RCL K
          15
          X<=Y?
          GTO 08
          <Place FOR/NEXT body code here>
          1
          STO+ K
        GTO 07
        LBL 08
        1
        STO+ J
      GTO 04
      LBL 05
      1
      STO+ I
    GTO 01
    LBL 02
    
    I realize this program is not of particular use for people without legacy HP calculator, but the point is that the Tokenizer module is very well suited for such a conversions. I would probably go crazy inventing that calculator code from the scratch, with script help it is very comfortable.

    I attach the commented code for possible study.


    Petr
    Attached Files Attached Files
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •