Oxygen Basic

Programming => Example Code => Data Processing => Topic started by: Aurel on September 22, 2014, 09:35:44 AM

Title: Ruben - simple interpreter
Post by: Aurel on September 22, 2014, 09:35:44 AM
Hi to all...
If anyone wish to try how work or to see how is created this small and simple
direct or tokenized interpreter written in Oxygen basic in attachment is complete
release with source code .
Every part of interpreter and code editor is written in Oxygen Basic.
(thanks to Charles ) ..  :) 



.
Title: Re: Ruben - simple interpreter
Post by: Aurel on February 17, 2015, 02:20:39 PM
..and here is a small screenshot  ( mouse move circles)...

.
Title: Re: Ruben - simple interpreter
Post by: Peter on February 18, 2015, 05:37:04 AM
Hi Aurel,

there comes along an error with ruben2.
if you click onto the window,  then start it again and again.  >:(

is this a new mesh by you?


.
Title: Re: Ruben - simple interpreter
Post by: Aurel on February 18, 2015, 06:35:57 AM
Quote
is this a new mesh by you?
yes Peter it is by me or by strange o2 trigering.... :-[
Title: Re: Ruben - simple interpreter
Post by: Aurel on February 18, 2015, 06:59:32 AM
No i mess up messages... ::)
I hope that is now fixed....
source is updated and is in folder RubSrc

.
Title: Re: Ruben - simple interpreter
Post by: Aurel on February 20, 2015, 05:13:27 AM
mayaM ...

Code: [Select]
wform 0,0,600,480,#SYS,0,"mayaM"
wcolor 0,0,0
txcolor 200,220,250
defn pi,rr,gg,bb,n
set pi = 3.14
defn level,angle,i
defn insize,x1,y1,x2,y2,d
set level = 300,angle = 0
set x1=200,y1=200

for n,0,100
 set angle=angle + 20

for i,1,9
    set d=9
   set x2 = x1 + cos(angle/d) * (d*10)
   set y2 = y1 + sin(angle*d)*2 * (d*10)
   set rr=RAND(255),gg=RAND(255),bb=250
   txcolor rr,gg,bb
   Line x2,y2,x1,y1
   circle x2,y2,d
   
   set angle=angle - 20
   
   set d=d-1
next i
next n 
 

.
Title: Re: Ruben - simple interpreter
Post by: Peter on February 20, 2015, 11:25:10 AM
Aurel, for what is pi here?
Title: Re: Ruben - simple interpreter
Post by: Aurel on February 20, 2015, 12:37:40 PM
hi Peter
Just for testing ..
Title: Re: Ruben - simple interpreter
Post by: Aurel on March 06, 2015, 02:17:06 PM
I just can confirm that ruben3 work under new oxygen dll
also @mousemove event work fine  :)

Code: [Select]
'@mousemove
wform 0,0,600,400,#MMS,0,"Mouse Move test"
defn y,y2,rr,gg,bb
defn mx,my,rc
'set my = 100


WAIT 0

@MOUSEMOVE

@MOUSEX mx
@MOUSEY my
set rc = RAND(10)
set rr=RAND(255),gg=RAND(155),gg=RAND(255)
txcolor 0,0,0,rr,gg,bb
circle mx,my,rc

@OFF

.
Title: Re: Ruben - simple interpreter
Post by: Aurel on March 07, 2015, 04:38:08 PM
well it looks that left mouse button down work fine

Code: [Select]
'@mousemove + left button down
wform 0,0,600,400,#MMS,0,"Mouse Move test"
defn y,y2,rr,gg,bb
defn mx,my,rc

WAIT 0

@MOUSEMOVE

@MOUSEX mx
@MOUSEY my

set rr=RAND(255),gg=RAND(155),gg=RAND(255)
txcolor 0,0,0,rr,gg,bb
set rc = RAND(10)
circle mx,my,rc

@OFF

@LEFTMBDOWN
txcolor 0,0,200,255,255,255
circle mx,my,30
@OFF


.
Title: Re: Ruben - simple interpreter
Post by: Peter on March 08, 2015, 03:19:44 AM
RubenDev Circles.
Code: [Select]
include "ss.inc"
window 600,400,1
cls 255,255,255

int y,y2,rr,gg,bb
int mx,my,rc

while keydown(27)=0
'cls 255,255,255
mx = xMouse
my = yMouse

rc = rand(8,20)
color rand(32,255),rand(32,155),rand(32,255),255
fillcircle mx,my,rc

if MouseButton()=1
   color 0,0,0,255
   drawcircle mx,my,40
endif

color 0,0,0,255
drawstring 200,16,"RUBENDEV CIRCLES"
redraw
wait 10
wend
winExit
Title: Re: Ruben - simple interpreter
Post by: Aurel on March 08, 2015, 10:52:35 AM
Work great Peter  :D
This is SDL example right ?
it is interesting that your o2 example use 26 GDI objects ad ruben need 48
and is strange that in some cases not work ...looks like DC coruption or something  >:(

Peter
do you can create same program with GDI only ?
if is not problem for you ...
i am interested how pure GDI o2 program work
thnks...
Title: Re: Ruben - simple interpreter
Post by: Aurel on April 26, 2015, 09:41:11 AM
just a small bug-fix ...


.
Title: Re: Ruben - simple interpreter
Post by: JRS on April 26, 2015, 10:20:03 AM
Aurel,

Can you post of list of features you plan to add to your BASIC going forward? It's better to warn folks ahead of time so they aren't disappointed with a surprise. Don't give up on Ruben as it helps Charles make O2 more stable and lets Charles think about alternative ways.
Title: Re: Ruben - simple interpreter
Post by: Aurel on April 27, 2015, 09:07:01 AM
Quote
Aurel,
Can you post of list of features you plan to add to your BASIC going forward? It's better to warn folks ahead of time so they aren't disappointed with a surprise. Don't give up on Ruben as it helps Charles make O2 more stable and lets Charles think about alternative ways.

Hi John
I will continue with ruben...currently i don't have enough free time..
well what i have in plan..hmm i am not sure.
currently ...ruben is very primitive interpreter few graphic commands and just float varible type
math function,few window controls ...
so i must add
 event-messages
more controls & related commands
strings & string operations
(this culd be tricky & little bit in unusual style)  ::)
probably some sort of container/asociative array ..or
(maybe with OOP - i like OOP things in o2)  ;)
html control or something similar
(via EB dll- seems that work so-so)
Title: Re: Ruben - simple interpreter
Post by: JRS on April 27, 2015, 09:28:05 AM
You may want to look at the My-BASIC source to get a few ideas how to handle some of the core BASIC logic for Ruben.
Title: Re: Ruben - simple interpreter
Post by: Aurel on April 28, 2015, 04:16:43 AM
Yes i can and i already did that...
but concept is completely different...
Title: Re: Ruben - simple interpreter
Post by: Aurel on April 28, 2015, 12:56:55 PM
i found this on ALLBASIC forum:

This is how I would do it if I were creating a basic interpreter. Here is the BNF description for TinyBasic

<line> = <number> <statement> <CR>
         <statement> <CR>
<statement> = PRINT <printlist>
              PR <printlist>
              INPUT <varlist>
              LET <var> = <expression>
              <var> = <expression>
              GOTO <expression>
              GOSUB <expression>
              RETURN
              IF <expression> <relop> <expression> THEN <statement>
              IF <expression> <relop> <expression> <statement>
              REM <commentstring>
              CLEAR
              RUN
              RUN <exprlist>
              LIST
              LIST <exprlist>
<printlist> =
              <printitem>
              <printitem> :
              <printitem> <separator> <printlist>
<printitem> = <expression>
              "<characterstring>"
<varlist> = <var>
            <var> , <varlist>
<exprlist> = <expression>
             <expression> , <exprlist>
<expression> = <unsignedexpr>
               + <unsignedexpr>
               - <unsignedexpr>
<unsignedexpr> = <term>
                 <term> + <unsignedexpr>
                 <term> - <unsignedexpr>
<term> = <factor>
         <factor> * <term>
         <factor> / <term>
<factor> = <var>
           <number>
           ( <expression> )
           <function>
<function> = RND ( <expression> )
             USR ( <exprlist> )
<number> = <digit>
           <digit> <number>
<separator> = , | ;
<var> = A | B | ... | Y | Z
<digit> = 0 | 1 2 | ... | 9
<relop> = < | > | = | <= | >= | <> | ><
Title: Re: Ruben - simple interpreter
Post by: Aurel on April 28, 2015, 01:16:53 PM
..also i found old topic by SteveA( i miss this guy)..
interesting he use same Factor() & term() in his expression parser
like me in ruben ( but i ue this for expression evaluator) ..funny.

Code: [Select]
SUB Term()
    Local ch$, pii, tValue, ismultop, ich

    Factor()
    tValue = dreturn
    pii = epos
    ch$ = pstring$(pii)

    IsMultop(ch$)
    ismultop = ireturn
   
    WHILE (ismultop = 1)
        ich = ASC(ch$)

        SWITCH ich
            CASE 42
                Match()
                Factor()
                tValue = tValue * dreturn
                BREAK
            CASE 47
                Match()
                Factor()
                tValue = tValue / dreturn
                BREAK
            CASE 94
                Match()
                Factor()
                tValue = tValue ^ dreturn
                BREAK
            CASE 37
                Match()
                Factor()
                ireturn = INT(dreturn)
                tValue = INT(tValue)
                tValue = mod(tValue, ireturn)
                BREAK
        END SWITCH

        pii = epos
        ch$ = pstring$(pii)
        IsMultop(ch$)
        ismultop = ireturn
    WEND

    dreturn = tValue
END SUB
' ---------- end Term ----------


SUB Factor()
    Local ch$, pii, isalpha, fvalue

    pii = epos
    ch$ = pstring$(pii)

    IF (ch$ = "(") THEN
         Match()
         Expression()
        fvalue = dreturn
        Match()
    ELSE
        GetNum()
        fvalue = dreturn
    ENDIF

    dreturn = fvalue
END SUB
' ---------- end Factor ----------
Title: Re: Ruben - simple interpreter
Post by: JRS on April 28, 2015, 01:21:39 PM
Quote
i found this on ALLBASIC forum:

There is a lot of good stuff there posted by multiple BASIC developers. Definitely a good place to check out if building your own BASIC interpreter is your life time goal.

I'm speaking as someone that picked up a production stable BASIC to carry on with. I can only imagine what it would be like writing it from scratch.  :o
Title: Re: Ruben - simple interpreter
Post by: Mike Lobanovsky on April 28, 2015, 01:54:51 PM
Actually Ed Davis' Toy interpreter is a very good place to start at. It is bytecode-driven (hence fast) and extendable. Fixed size arrays for its code and variable storage are currently its only limitation that can be easily overcome in O2 using array pointer overlays as necessary and msvcrt.dll's malloc() or calloc() and free() functions to manage the code/program memory in real time.
Title: Re: Ruben - simple interpreter
Post by: Aurel on April 29, 2015, 03:47:32 AM
Quote
I can only imagine what it would be like writing it from scratch.
well ...i like it -from scratch,scratch....scratch
it is more funny than use already created   ::)
Title: Re: Ruben - simple interpreter
Post by: JRS on April 29, 2015, 07:37:43 AM
Quote
scratch
it is more funny than use already created

Translation: It's more fun than using an existing BASIC project.

If I was young and fearless like you, I might agree.