JB to C toy translator

Programming Tools, Tips, and Tutorials.
tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

JB to C toy translator

Post by tsh73 » Wed Dec 25, 2013 5:35 am

explained here
http://justbasic.conforums.com/index.cg ... 1386761972
Now initial project goals are met so I call it v.1.0 - it supports:
* numerical variables (as C double)
* print, input
* text constants in print, input (to be used as prompts)
* for (with optional step, negative step works too)
* if (only block version, with end if)
* assignment (expressions are left as is, except "=time$("ms")" changed to "=clock()" - quick hack to allow program timing)
Only single operator on a line.
Extra:
* '-style comments converts to //comments
* unrecognized lines cconverted to //??? comments
* labels and GOTO are implemented. So you can simulate WHILE loops.
GUI attempts to compile converted code with Tiny C Compiler, http://en.wikipedia.org/wiki/Tiny_C_Compiler
Path to compiler should be set via Options menu.
Archive contains
1) GUI version,
2) example BAS file that shows all program capabilities,
3) and non-gui version that reads example BAS file converst it and dumps to mainwin.
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Sat Dec 28, 2013 7:18 pm

v.1.1, Dec 28 2013
* added:
EXIT FOR
WHILE/WEND, EXIT WHILE
DO/LOOP (all variants), EXIT DO
*demo file for version 1.1
demo1.1.bas
(demo for previous version named demo1.0.bas)
* added function returning version (jb2cConv.ver$(), jb2cGUI.ver$()),
version info displayed in Help/About
* major rewrite - operators in select case ordered alphabetically
* added this file (History.txt)
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Mon Dec 30, 2013 12:05 pm

v.1.2, Dec 30 2013
added:
* Several operators on a line, like
x=1: y=2
* continuation lines, like
print "x=", _
x, "y=", y
* single-line IF, like
IF condition then operator
IF condition then operator1[: operator 2]
IF condition then operator1[: operator 2] else operator 3[: operator 4]
, you know.
- two IF on single line will fail.
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Tue Dec 31, 2013 8:18 am

Code: Select all

v.1.3, Dec 31 2013
Changed:
* better PRINT handling
    separated by (;) prints without gaps
    separated by (,) prints via TAB
    print without new line
        print ends by (;)
        print ends by (,)
* nested single line IF
    actually, only form that makes sense is
    IF cond1 then op1 else if cond 2 then op2 ... else opElse
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Sat Jan 11, 2014 2:12 pm

Code: Select all

GUI change
 v.1.1, Dec 31 2013
* log pane converted from texteditor to listbox.
    Now, if you get error after compiling, like
        temp.c:26: ';' expected
    and double click on it, "Generated C source" pane will position
    just above offending line (in ths case - on line 25).
    Because often, cause of error is on previous line.
* better handling of compiler output:
    now it checks compiler return codes (creates files for "ok" or "fail")
    instead of checking for presence of EXE file.

--------------------------------------------------------------
 convertor v.1.4, Jan 11 2014
 Fixed:
 * a case then unterminated string in PRINT hang convertor
    (I am not saying it will not hang - there basically no error checking -
    it'll just not hang in this special case)
 Added:
 * RND(1) support
 (RND, RANDOMIZE, and initial call to srand(time(0));)

 GUI v.1.2, Jan 11 2013
 Added:
 * option for RND support
 * option for math support (basically, to include MATH.H)
    - not used yet
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Wed Jan 22, 2014 9:25 am

Code: Select all

 convertor v.1.5, Jan 22 2014
 Added:
 * math support
    included <math.h>, some functions aliased
    int() and abs() skipped for now
    MOD and ^ postponed until expression gets rewritten
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Fri Jan 31, 2014 4:49 pm

convertor v.1.6, Jan 29 2014
Added:
* built-in min, max: (required changing parsing print arguments)

GUI v.1.3, Jan 29 2013
Added:
* option for built-in min, max support
Changed:
* asking for binary options converted to function
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Sat Feb 01, 2014 5:16 pm

Code: Select all

 convertor v.1.7, Feb 01 2014
 Added: 
 * data/read/restore
  - No "restore label" yet
  - Read past end of data end program with message
    ERROR: Read past end of data
 * cls (thanks to Plus3Code for C equivalent)
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Sun Feb 02, 2014 10:23 am

Code: Select all

 convertor v.1.8, Feb 02 2014
 Added: 
 * run
  - run command
  - run command, mode
    only min, max (no hide or noActive)
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Sun Feb 02, 2014 3:24 pm

Code: Select all

 convertor v.1.9, Feb 02 2014
 Changed: 
 * restore label
 is supported.
 Attempt to restore non-existing label, say
   restore 21
 ends up with C compiler message
   'restore_lbl_21' undeclared
You do not have the required permissions to view the files attached to this post.

tsh73
Posts: 42
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 » Mon Feb 03, 2014 7:14 am

Code: Select all

 convertor v.1.10, Feb 03 2014
 Changed:
* numeric expressions are passed through numExprRewrite$(expr$)
  function, which does some search/replace.
  So here we got:
  - abs(), int() now supported (if MATH support is ON).
  So we have all math functions except MOD and ^ (!)
  - case is fixed to all functions. So Sin(), RND() all works
  - numExprRewrite$ called in condRewrite$ too, 
    so same things work in conditions.
You do not have the required permissions to view the files attached to this post.