Author Topic: Ruben - simple interpreter  (Read 8219 times)

0 Members and 1 Guest are viewing this topic.

John

  • Hero Member
  • *****
  • Posts: 3706
Re: Ruben - simple interpreter
« Reply #15 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.

Aurel

  • Guest
Re: Ruben - simple interpreter
« Reply #16 on: April 28, 2015, 04:16:43 AM »
Yes i can and i already did that...
but concept is completely different...
« Last Edit: April 28, 2015, 09:05:33 AM by Aurel »

Aurel

  • Guest
Re: Ruben - simple interpreter
« Reply #17 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> = < | > | = | <= | >= | <> | ><

Aurel

  • Guest
Re: Ruben - simple interpreter
« Reply #18 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 ----------

John

  • Hero Member
  • *****
  • Posts: 3706
Re: Ruben - simple interpreter
« Reply #19 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

Mike Lobanovsky

  • Hero Member
  • *****
  • Posts: 1993
Re: Ruben - simple interpreter
« Reply #20 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.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Aurel

  • Guest
Re: Ruben - simple interpreter
« Reply #21 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   ::)

John

  • Hero Member
  • *****
  • Posts: 3706
Re: Ruben - simple interpreter
« Reply #22 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.
« Last Edit: April 29, 2015, 12:55:21 PM by John »