Jump to content
matthew180

BASIC / XB Translator (TidBit)

Recommended Posts

9 hours ago, Vorticon said:

I don't know about less code, but definitely a better structured program with clearly defined  and controlled subroutine parameters. I rely on them heavily.

A SUB creates a list of Temporary variable separate from normal Variables, this saves memory in VDP.

Share this post


Link to post
Share on other sites

Where are the local variables for the SUB kept Rich? (Never looked into this stuff)

Share this post


Link to post
Share on other sites
12 hours ago, TheBF said:

Where are the local variables for the SUB kept Rich? (Never looked into this stuff)

A temporary VDP Buffer is set up and as the main variables already have the values after completion there is no need to save them.

This works the same way as a DSR VDP buffer, it is set up and used but deleted when done.

  • Like 1

Share this post


Link to post
Share on other sites
On 11/17/2019 at 10:17 PM, matthew180 said:

 

Ok, looking into it now.  Can you give me a few lines of the actual code?  Also note, labels that collide with reserved words are silently ignored.

 

Here you go:

 

OPEN #1:"RS232".BA=9600.DA=7,UPDATE !OPEN SERIAL COMM WITH ROBOT
PRINT #1:5 !SEND MOVE FORWARD CODE TO ROBOT
fwd_complete:
ON ERROR fwd_complete::INPUT #1:ANS$ !WAIT FOR CONFIRMATION FROM ROBOT
ON ERROR STOP !RESUME NORMAL ERROR TRAPPING
IF ANS$<>"89" THEN fwd_complete !KEEP CHEKCING UNTIL CORRECT CODE RECEIVED
...

The fwd_complete label does not resolve to a line number inside the ON ERROR line, but it does outside of it.

Share this post


Link to post
Share on other sites
On 11/18/2019 at 2:00 AM, matthew180 said:

Ok, the double-colon problem is now fixed, and it also fixes the problem posted in #219 above.  I have updated the download file on the first page of this post (V3.1), as well as my website.

 

Also, Vorticon, I'm not sure if you realize but you don't need the continuation operator ".." if the line ends with the double-colon.  I have not seen your tidbit code recently, but the examples you posted many moons ago showed you were still using the ":: .." syntax.

A=1 ::
B=2 ::
C=3 ::

Translates to:

A=1::B=2::C=3

You *don't* need to do this (since somewhere around 2015 or 2016 I think)

A=1 :: ..
B=2 :: ..
C=3

 

Noted. Thanks.

Share this post


Link to post
Share on other sites
2 hours ago, Vorticon said:

The fwd_complete label does not resolve to a line number inside the ON ERROR line, but it does outside of it.

This is fixed now, since Monday. :)

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

I found another bug related to ON ERROR.

 

ON ERROR err_sub

INPUT #1:ANS$

...

continue:

PRINT "HELLO"

END

...

err_sub

PRINT "ERROR!"

RETURN continue  <--- this label is not converted to a line number

Quote

 

 

Share this post


Link to post
Share on other sites

The word "continue" is a reserved word and cannot be used as a label.  Right now, any reserved words that are used as labels are silently ignored, i.e. they will pass through unmodified.  If you change the code above to something like this, it will work:

 

ON ERROR err_sub
INPUT #1:ANS$

err_continue:
PRINT "HELLO"
END

err_sub:
  PRINT "ERROR!"
  RETURN err_continue

----------------

100 ON ERROR 140
110 INPUT #1:ANS$
120 PRINT "HELLO"
130 END
140 PRINT "ERROR!"
150 RETURN 120

If you have any suggestions as to what to do about labels that conflict with reserved words, please let me know.  To keep the parser simple it does not actually interpret the code, so it does not have the context to know the difference between a label's use and a real BASIC statement/word (which is why all BASIC and XB statements/words are reserved and cannot be used for labels).  Currently, this is the list:

 

    private $reserved_words = array(
        'abs', 'accept', 'all', 'and', 'append', 'asc', 'at', 'atn',
        'base', 'beep', 'break', 'bye',
        'call', 'chr$', 'close', 'con', 'continue', 'cos',
        'data', 'def', 'delete', 'digit', 'dim', 'display',
        'else', 'end', 'eof', 'erase', 'error', 'exp',
        'fixed', 'for',
        'go', 'gosub', 'goto',
        'if', 'image', 'input', 'int', 'internal',
        'len', 'let', 'linput', 'list', 'log',
        'max', 'merge', 'min',
        'new', 'next', 'not', 'num', 'number', 'numeric',
        'old', 'on', 'open', 'option', 'or', 'output',
        'permanent', 'pi', 'pos', 'print',
        'randomize', 'read', 'rec', 'relative', 'rem', 'res', 'resequence', 'restore', 'return', 'rnd', 'rpt$', 'run',
        'save', 'seg$', 'sequential', 'sgn', 'sin', 'size', 'sqr', 'step', 'stop', 'str$', 'sub', 'subend', 'subexit',
        'tab', 'tan', 'then', 'to', 'trace',
        'ualpha', 'unbreak', 'untrace', 'update', 'using',
        'val', 'validate', 'variable',
        'warning',
        'xor'
        );

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...