JB to C toy translator

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

JB to C toy translator

Post by tsh73 »

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.
Attachments
jb2c_v1.0.zip
(9.95 KiB) Downloaded 2712 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

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)
Attachments
jb2c_v1.1.zip
(43.18 KiB) Downloaded 2318 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

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.
Attachments
jb2c_v1.2.zip
(13.88 KiB) Downloaded 2833 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

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
Attachments
jb2c_v1.3.zip
(14.55 KiB) Downloaded 2352 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

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
Attachments
jb2c_v1.4.zip
(15.78 KiB) Downloaded 2165 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

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
Attachments
jb2c_v1.5.zip
(17.05 KiB) Downloaded 2510 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

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
Attachments
jb2c_v1.6.zip
(17.49 KiB) Downloaded 2442 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

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)
Attachments
jb2c_v1.7.zip
(18.86 KiB) Downloaded 2235 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

Code: Select all

 convertor v.1.8, Feb 02 2014
 Added: 
 * run
  - run command
  - run command, mode
    only min, max (no hide or noActive)
Attachments
jb2c_v1.8.zip
(19.6 KiB) Downloaded 2715 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

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
Attachments
jb2c_v1.9.zip
(20.55 KiB) Downloaded 2198 times
tsh73
Posts: 46
Joined: Fri May 04, 2007 12:03 pm

Re: JB to C toy translator

Post by tsh73 »

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.
Attachments
jb2c_v1.10.zip
(22.45 KiB) Downloaded 2278 times
Post Reply