Author Topic: MY-BASIC  (Read 118071 times)

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #165 on: February 23, 2016, 10:40:28 AM »
Oh, I think that's not the problem. My function does the following:
Code: [Select]
if (windowclosehandler!=0) {
windowclosehandler=1;
}
   

also this code works:
Code: [Select]
do
'... other code
until (keystate (KEY_ESC) = true) or (windowclosed=true)

And another question; is it possible to initialize an array with values? Would be handy for level data, something like:
Code: [Select]
dim x(2,2)=((1,1),(2,2))
Apart from that a DATA statement would be nice ...
« Last Edit: February 23, 2016, 11:10:15 AM by Cybermonkey342 »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #166 on: February 23, 2016, 06:03:21 PM »
Markus,

I've tried a simple test case, which works fine without prompting anything as expected:

Code: PHP
  1. windowclosed = true
  2. if windowclosed = true then
  3.     end
  4. endif
  5. print "impossible";

So I think the problem is not simply within the test case. Would you provide a minimum full code which reproduce the bug?

It's not possible to initialize an array with values for the moment, I'll think over it.

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #167 on: February 23, 2016, 07:17:19 PM »
Markus, I've added a TO_ARRAY statement to make an array from a list, while lists are easy to initialize with data:

Code: PHP
  1. l = list(0, 1, 2)
  2. a = to_array(l)
  3. print a(0); a(1); a(2);
  4. print len(a);
« Last Edit: February 23, 2016, 07:29:26 PM by wangrenxin »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #168 on: February 23, 2016, 07:32:11 PM »
Wang,

Does that work with string lists?

John

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #169 on: February 23, 2016, 08:50:37 PM »
Does that work with string lists?

Yes, but it needs to undefine the MB_SIMPLE_ARRAY macro in my_basic.h.

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #170 on: February 24, 2016, 08:48:05 AM »
First thanks for the to_array statement. I'll try that later.
Here's the complete code (again the fractals):
Code: Text
  1. screen (256,256,"Fractal")
  2.  
  3. bx=0
  4. by=0
  5. bw=256
  6. bh=256
  7.  
  8. sx=-2.2
  9. sy=-1.7
  10. sw=3.4
  11. sh=3.4
  12.  
  13. cls
  14. time1=tickcount
  15. for x=bx to bx+bw
  16.  for y=by to by+bh
  17.    gx=(x-bx)/bw*sw+sx
  18.    gy=(y-by)/bh*sh+sy
  19.    zx=gx
  20.    zy=gy
  21.    for c=0 to 255
  22.     col = c
  23.     nzx=zx*zx - zy*zy + gx
  24.     zy=2*zx*zy+gy
  25.     zx=nzx
  26.     if zx*zx + zy*zy > 4 then
  27.     col = c
  28.     exit
  29.     endif
  30.   next
  31.   r = col*256+col*32*0.5
  32.   v = col*256+col*64*0.5
  33.   b = col*256+col*32*0.8      
  34.   ink (r,v,b)
  35.   pset (x,y)
  36.   if windowclosed = true then
  37.    end
  38.   endif
  39.  next
  40. redraw
  41. next
  42.  
  43. time2=tickcount
  44. ink (255,255,255)
  45. timex=(time2-time1)/1000
  46. drawtext (0,0,"Time needed: "+str (timex)+" seconds")
  47. sync
  48. inkey
  49. end

It's the lines 36 to 38. If I change the line 37 e.g. with exit (or any other statement), it is recognized, but not the end statement. Maybe because of the loops? This also didn't work with the old version. Only this did work:
Code: [Select]
if windowclosed = true then end
But in the actual version it doesn't work anymore.

Is it possible to convert lists to 2-dimensional arrays?
« Last Edit: February 25, 2016, 07:17:09 PM by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #171 on: February 24, 2016, 08:17:34 PM »
Markus, thank your for your code, I figured out the problem due to your code. It went wrong since I'd refactored the FOR loop a few weeks ago. I've fixed it, and you can test it with following code:

Code: Text
  1. gosub sub
  2. end
  3. sub:
  4.     for j = 0 to 1
  5.         for i = 0 to 10
  6.             print i, ", ", j;
  7.             v = i > 3
  8.             if v = true then
  9.                 end ' Can be replaced with "return"
  10.             endif
  11.         next
  12.     next
  13.     return

Is it possible to convert lists to 2-dimensional arrays?

Yep it's possible. I prefer to implement it in script:

Code: Text
  1. def to_2d_array(l, d0, d1)
  2.     dim ret(d0, d1)
  3.     for j = 0 to d1 - 1
  4.         for i = 0 to d0 - 1
  5.             ret(i, j) = l(j * d0 + i)
  6.         next
  7.     next
  8.     return ret
  9. enddef
  10. a = to_2d_array(list(0, 1, 2, 3), 2, 2)
  11. print a(0, 0); a(1, 0); a(0, 1); a(1, 1);
« Last Edit: February 25, 2016, 07:16:37 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #172 on: February 24, 2016, 10:32:47 PM »
Wang & Markus,

If you guys want to create a GeSHi syntax definition file for your BASIC languages, I will include them here on the forum for you to use.

Here is the Script BASIC (sb) syntax definition file.

Code: PHP
  1. <?php
  2. /*************************************************************************************
  3.  * sb.php
  4.  *
  5.  * Author: John Spikowski (support@scriptbasic.org)
  6.  *
  7.  * Script BASIC language file for GeSHi.
  8.  *
  9.  *************************************************************************************
  10.  *
  11.  *     This file is part of GeSHi.
  12.  *
  13.  *   GeSHi is free software; you can redistribute it and/or modify
  14.  *   it under the terms of the GNU General Public License as published by
  15.  *   the Free Software Foundation; either version 2 of the License, or
  16.  *   (at your option) any later version.
  17.  *
  18.  *   GeSHi is distributed in the hope that it will be useful,
  19.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  *   GNU General Public License for more details.
  22.  *
  23.  *   You should have received a copy of the GNU General Public License
  24.  *   along with GeSHi; if not, write to the Free Software
  25.  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  26.  *
  27.  ************************************************************************************/
  28.  
  29. $language_data = array (
  30.     'LANG_NAME' => 'Script BASIC',
  31.     'COMMENT_SINGLE' => array(),
  32.     'COMMENT_MULTI' => array(),
  33.     'COMMENT_REGEXP' => array(
  34.         // Comments (either single or multiline with _
  35.         1 => '/\'.*(?<! _)\n/sU',
  36.         ),
  37.     'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
  38.     'QUOTEMARKS' => array('"'),
  39.     'ESCAPE_CHAR' => '',
  40.     'KEYWORDS' => array(
  41.         1 => array(
  42.             'ABS', 'ACOS', 'ACOSECANT', 'ACTAN', 'ADDDAY', 'ADDHOUR', 'ADDMINUTE', 'ADDMONTH', 'ADDRESS', 'ADDSECOND', 'ADDWEEK', 'ADDYEAR', 'ALIAS', 'AND', 'AS', 'ASC', 'ASECANT', 'ASIN', 'ATAN', 'ATN',
  43.             'BIN', 'BINMODE', 'BY', 'BYVAL',
  44.             'CALL', 'CHDIR', 'CHOMP', 'CHR', 'CHR$', 'CINT', 'CLOSE', 'CLOSEALL', 'COMMAND', 'CONF', 'CONST', 'COS', 'COSECANT', 'COTAN', 'COTAN2', 'CRYPT', 'CURDIR', 'CVD', 'CVI', 'CVL', 'CVS',
  45.             'DAY', 'DECLARE', 'DELETE', 'DELTREE', 'DIRECTORY', 'DO', 'ELIF', 'ELSE', 'ELSEIF', 'ELSIF', 'END', 'ENDIF', 'ENVIRON', 'ENVIRON$', 'EOD', 'EOF', 'ERROR', 'ERROR$', 'EVEN', 'EXECUTE', 'EXIT', 'EXP',
  46.             'FALSE', 'FILE', 'FILEACCESSTIME', 'FILECOPY', 'FILECREATETIME', 'FILEEXISTS', 'FILELEN', 'FILEMODIFYTIME', 'FILEOWNER', 'FIX', 'FOR', 'FORK', 'FORMAT', 'FORMATDATE', 'FORMATTIME', 'FRAC', 'FREEFILE', 'FROM', 'FUNCTION',
  47.             'GCD', 'GLOBAL', 'GMTIME', 'GMTIMETOLOCALTIME', 'GO', 'GOSUB', 'GOTO',
  48.             'HCOS', 'HCOSECANT', 'HCTAN', 'HEX', 'HEX$', 'HOSTNAME', 'HOUR', 'HSECANT', 'HSIN', 'HTAN',
  49.             'ICALL', 'IF', 'IMAX', 'IMIN', 'IMPORT', 'INPUT', 'INSTR', 'INSTRREV', 'INT', 'ISARRAY', 'ISDEFINED', 'ISDIRECTORY', 'ISEMPTY', 'ISFILE', 'ISINTEGER', 'ISNUMERIC', 'ISREAL', 'ISSTRING', 'ISUNDEF',
  50.             'JOIN', 'JOKER',
  51.             'KILL',
  52.             'LBOUND', 'LCASE', 'LCASE$', 'LCM', 'LEFT', 'LEFT$', 'LEN', 'LET', 'LIB', 'LIKE', 'LINE', 'LOC', 'LOCAL', 'LOCALTIMETOGMTIME', 'LOCK', 'LOF', 'LOG', 'LOG10', 'LOOP', 'LOWER', 'LOWER$', 'LTRIM', 'LTRIM$',
  53.             'MAX', 'MAXINT', 'MID', 'MID$', 'MIN', 'MININT', 'MINUTE', 'MKD', 'MKD$', 'MKDIR', 'MKI', 'MKI$', 'MKL', 'MKL$', 'MKS', 'MKS$', 'MODULE', 'MONTH',
  54.             'NAME', 'NEXT', 'NEXTFILE', 'NO', 'NOT', 'NOW', 'NULL',
  55.             'OCT', 'OCT$', 'ODD', 'ON', 'OPEN', 'OPTION', 'OR', 'OUTPUT',
  56.             'PACK', 'PATTERN', 'PAUSE', 'PI', 'POP', 'POW', 'PRINT', 'PRINTNL',
  57.             'QUOTE',
  58.             'RANDOMIZE', 'REF', 'REGION', 'REPEAT', 'REPLACE', 'RESET', 'RESUME', 'RETURN', 'REWIND', 'RIGHT', 'RIGHT$', 'RND', 'ROUND', 'RTRIM', 'RTRIM$',
  59.             'SEC', 'SECANT', 'SEEK', 'SET', 'SGN', 'SIN', 'SLEEP', 'SPACE', 'SPACE$', 'SPLIT', 'SPLITA', 'SPLITAQ', 'SQR', 'STEP', 'STOP', 'STR', 'STR$', 'STRING', 'STRING$', 'STRREVERSE', 'STRREVERSE$', 'SUB', 'SWAP', 'SYSTEM',
  60.             'TAN', 'TAN2', 'TEXTMODE', 'THEN', 'TIME', 'TIMEVALUE', 'TO', 'TRIM', 'TRIM$', 'TRUE', 'TRUNCATE', 'TYPE',
  61.             'UBOUND', 'UCASE', 'UCASE$', 'UNDEF', 'UNPACK', 'UNTIL', 'UPPER', 'UPPER$',
  62.             'VAL', 'VAR', 'VBCALL', 'VBNEW', 'VBREL',
  63.             'WAITPID', 'WEEKDAY', 'WEND', 'WHILE', 'WILD',
  64.             'XOR',
  65.             'YEAR', 'YEARDAY'
  66.             ),
  67.         ),
  68.     'SYMBOLS' => array(
  69.         ),
  70.     'CASE_SENSITIVE' => array(
  71.         GESHI_COMMENTS => false,
  72.         1 => false,
  73.         2 => false,
  74.         3 => false,
  75.         4 => false,
  76.         5 => false,
  77.         6 => false
  78.         ),
  79.     'STYLES' => array(
  80.         'KEYWORDS' => array(
  81.             1 => 'color: #000080; font-weight: bold;',
  82.             ),
  83.         'COMMENTS' => array(
  84.             1 => 'color: #008000;'
  85.             ),
  86.         'BRACKETS' => array(
  87.             ),
  88.         'STRINGS' => array(
  89.             0 => 'color: #800000;'
  90.             ),
  91.         'NUMBERS' => array(
  92.             ),
  93.         'METHODS' => array(
  94.             ),
  95.         'SYMBOLS' => array(
  96.             ),
  97.         'ESCAPE_CHAR' => array(
  98.             0 => 'color: #800000; font-weight: bold;'
  99.             ),
  100.         'SCRIPT' => array(
  101.             ),
  102.         'REGEXPS' => array(
  103.             )
  104.         ),
  105.     'URLS' => array(
  106.         1 => '',
  107.         2 => '',
  108.         3 => '',
  109.         4 => '',
  110.         5 => '',
  111.         6 => ''
  112.         ),
  113.     'OOLANG' => false,
  114.     'OBJECT_SPLITTERS' => array(
  115.         ),
  116.     'REGEXPS' => array(
  117.         ),
  118.     'STRICT_MODE_APPLIES' => GESHI_NEVER,
  119.     'SCRIPT_DELIMITERS' => array(
  120.         ),
  121.     'HIGHLIGHT_STRICT_BLOCK' => array(
  122.         ),
  123.     'PARSER_CONTROL' => array(
  124.         'ENABLE_FLAGS' => array(
  125.             'BRACKETS' => GESHI_NEVER,
  126.             'SYMBOLS' => GESHI_NEVER,
  127.             'NUMBERS' => GESHI_NEVER
  128.             )
  129.         )
  130. );
  131.  
  132. ?>
  133.  
« Last Edit: February 24, 2016, 10:39:35 PM by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #173 on: February 25, 2016, 03:02:21 AM »
It's nice to have, John.

Here's a keywords and reserved words list in MB:

NIL, MOD, AND, OR, NOT, IS, LET, DIM, IF, THEN, ELSEIF, ELSE, ENDIF, FOR, IN, TO, STEP, NEXT, WHILE, WEND, DO, UNTIL, EXIT, GOTO, GOSUB, RETURN, CALL, DEF, ENDDEF, CLASS, ENDCLASS, NEW, VAR, REFLECT, LAMBDA, MEM, TYPE, IMPORT, END

ABS, SGN, SQR, FLOOR, CEIL, FIX, ROUND, SRND, RND, SIN, COS, TAN, ASIN, ACOS, ATAN, EXP, LOG, ASC, CHR, LEFT, LEN, MID, RIGHT, STR, VAL, PRINT, INPUT

LIST, DICT, PUSH, POP, PEEK, INSERT, SORT, EXIST, INDEX_OF, GET, SET, REMOVE, CLEAR, CLONE, TO_ARRAY, ITERATOR, MOVE_NEXT

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #174 on: February 25, 2016, 11:14:49 AM »
@Wang: Yeah, thanks it works again as expected. I think I can release a new version of AllegroBASIC this weekend.

@John: AllegroBASIC uses all keywords from MY-BASIC and the following additional keywords:

TRUE, FALSE(did you forget them Wang? ;)), SCREEN, SLEEP, SYNC, REDRAW, CIRCLE, FILLCIRCLE, INK, PAPER, CLS, PSET, RECTANGLE, FILLRECTANGLE, LINE, SCREENWIDTH, SCREENHEIGHT, KEYPRESSED, INKEY, DRAWTEXT, TEXTSIZE, PAINT, ELLIPSE, FILLELLIPSE, FILLTRIANGLE, TRIANGLE, KEYSTATE, MOUSEX, MOUSEY, MOUSEBUTTON, MOUSEWHEEL, SHOWMOUSE, HIDEMOUSE, TICKCOUNT, LOADBMP, LOADIMAGE, DRAWSPRITE, DRAWIMAGE, SETFPS, IMAGEWIDTH, IMAGEHEIGHT, ROTATESPRITE, SCALESPRITE, ROTATESCALEDSPRITE, LOADWAV, LOADSOUND, PLAYSOUND, STOPSOUND, FOPEN, FCLOSE, FPEEK, FPOKE, FREAD, FREAD_LINE, FWRITE, FWRITE_LINE, MESSAGEBOX, INPUTBOX, TIME, FILEEXISTS, WINDOWCLOSED

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #175 on: February 25, 2016, 07:20:13 PM »
I put a combined mb (MyBASIC) syntax file on the server. If you add/change/remove keywords or enhance the the format I used for the Script BASIC file, let me know. (see changes to the last couple posts you guys made)

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #176 on: February 25, 2016, 09:35:56 PM »
@John, Thanks, it's prettier.

@Markus, Oops, forgot booleans indeed. I'm glad to help to make AllegroBASIC one more step forward.

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #177 on: February 26, 2016, 08:53:12 AM »
@John: Cool, thanks a lot!

@Wang: The most work on AllegroBASIC is done by you!  ;)
(AllegroBASIC has just about 1,400 lines of code and MY-BASIC? 16,000?)

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #178 on: February 28, 2016, 04:02:32 AM »
Allright guys, version 0.6 of AllegroBASIC is available on the homepage: http://allegrobasic.pulsar2d.org/
What's new?
  • included the tinyfiledialogs libarary for error output
  • added messagebox and inputbox (to replace PRINT and INPUT since there's no console window anymore)
  • added a TIME function which returns the time in format HH:MM:SS as a string
  • added drawspritepart and drawimagepart which let you draw part of a bitmap
  • added fileexists function
  • new about dialog in TinyIDE

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #179 on: February 28, 2016, 05:49:44 PM »
Cheers!