My_basic interpreter

For other topics related to the FreeBASIC project or its community.
aurelVZAB
Posts: 464
Joined: Jul 02, 2008 14:55
Location: [url]https://www.facebook.com/groups/470369984111370[/url]
Contact:

Re: My_basic interpreter

Postby aurelVZAB » Jan 29, 2021 7:53

Anyway, this probably isn't the right place to discuss C, and we've kind of hi-jacked the thread (It was about My_basic). If you want to discuss it more, feel free to email me.


Well we are under topic about basic interpreter written in C ....right?
Jwilla basic is also written in C ...ok?
Maybe we can continue under new topic if some other members are interested...?
And here are people who have experience in FreeBasic much more than Me.
You know i am better with o2 than with fb....heh

ps.By the way jj2007 our old masm friend said ...most people here visit this forum
just because sentimental reasons ,,,
aurelVZAB
Posts: 464
Joined: Jul 02, 2008 14:55
Location: [url]https://www.facebook.com/groups/470369984111370[/url]
Contact:

Re: My_basic interpreter

Postby aurelVZAB » Jan 30, 2021 12:43

I will just add this ..for fun

'define in pseudo code or not?
'in C
'int (*prg[PRGSZ])(void),(**pc)(void),cpc,lmap[PRGSZ]; /* COMPILED PROGRAM */
'is this basic like ?
int PRGSZ = 1024
int *prg[PRGSZ]) ' this is nothing else than integer array
'or
int prg[1024]
declare function (int pc) as INT
int cpc=0
int lmap[PRGSZ] 'this is nothing else than integer array
Ed Davis
Posts: 25
Joined: Jul 28, 2008 23:24

Re: My_basic interpreter

Postby Ed Davis » Jan 30, 2021 13:53

aurelVZAB wrote:I will just add this ..for fun

'define in pseudo code or not?
'in C
'int (*prg[PRGSZ])(void),(**pc)(void),cpc,lmap[PRGSZ]; /* COMPILED PROGRAM */
'is this basic like ?
int PRGSZ = 1024
int *prg[PRGSZ]) ' this is nothing else than integer array
'or
int prg[1024]
declare function (int pc) as INT
int cpc=0
int lmap[PRGSZ] 'this is nothing else than integer array


But remember, it is: int (*prg[PRGSZ])(void),(**pc)(void)

That says that prg is an array of pointers to functions, taking 0 parameters, and returning an integer.
And it makes pc a pointer to essentially the same thing.

For fun, go to here: https://cdecl.org/ and paste in: int (*prg[100])(void); and you'll be told what it means.

For instance:int (*prg[100])(void);
declare prg as array 100 of pointer to function (void) returning int

And: int (**pc)(void)
declare pc as pointer to pointer to function (void) returning int
aurelVZAB
Posts: 464
Joined: Jul 02, 2008 14:55
Location: [url]https://www.facebook.com/groups/470369984111370[/url]
Contact:

Re: My_basic interpreter

Postby aurelVZAB » Jan 30, 2021 21:33

Yes Ed
I know that you know all that things ...

and i see ..heh.... pointer to pointer with two stars **pc

But my question will be
Is this approach is really nececery for this tyoe of program ...?

i think not ...
but again maybe i am totaly stupid for all this pointered functions
Ed Davis
Posts: 25
Joined: Jul 28, 2008 23:24

Re: My_basic interpreter

Postby Ed Davis » Jan 30, 2021 22:53

aurelVZAB wrote:Yes Ed
I know that you know all that things ...
Nope. And I apologize if I come across that way. I only know enough to be dangerous. I'm ignorant in so many areas that it makes me very frustrated.
aurelVZAB wrote:and i see ..heh.... pointer to pointer with two stars **pc
But my question will be
Is this approach is really nececery for this tyoe of program ...?
i think not ...
No it isn't necessary. However, some folks (myself included) think that a table of function pointerss is much nicer than a huge case statement. But that is the nice thing about programming - you are free to do it the way you like best.
aurelVZAB wrote:but again maybe i am totaly stupid for all this pointered functions
Nah, you've written several Basic interpreters, and I've seen your posts on other topics. You're plenty smart. You just don't have lots of C experience.
aurelVZAB
Posts: 464
Joined: Jul 02, 2008 14:55
Location: [url]https://www.facebook.com/groups/470369984111370[/url]
Contact:

Re: My_basic interpreter

Postby aurelVZAB » Jan 31, 2021 12:31

You just don't have lots of C experience.


Yes Ed you have a right !
angros47
Posts: 1890
Joined: Jun 21, 2005 19:04

Re: My_basic interpreter

Postby angros47 » Mar 04, 2021 0:22

How to use a FreeBasic function from My_Basic:

Code: Select all

#include "my_basic.bi"
function maximum cdecl (s as any ptr, byref l as any ptr) as integer
   dim as integer result = MB_FUNC_OK
   dim as integer  m = 0
   dim as integer n = 0
   dim as integer r = 0
   mb_attempt_open_bracket(s, l)
   mb_pop_int(s, l, m)
   mb_pop_int(s, l, n)
   mb_attempt_close_bracket(s, l)
   r = iif(m > n, m , n)
   mb_push_int(s, l, r)
   return result
end function



dim bas as any ptr

mb_init()
mb_open(bas)
mb_register_func(bas, "maximum", @maximum)
mb_load_string(bas, "print maximum(22 , 7);", 1)
mb_run(bas, 1)
mb_close(bas)
mb_dispose
angros47
Posts: 1890
Joined: Jun 21, 2005 19:04

Re: My_basic interpreter

Postby angros47 » Jun 05, 2021 21:51

I was thinking to create a programming environment in FreeBasic, using My Basic as an interpreter. FreeBasic would be used to create the window, and to provide input. I wonder how should I manage the code input: one option is to make the program only able to read and execute a source code from a file (or from a pipe). Another is to make a simple text editor in FreeBasic, perhaps in text more, perhaps in graphic mode. I need ideas. Any suggestions?

Such an environment could be also integrated with OpenB3D, providing the ability to control it from a Basic script
BasicCoder2
Posts: 3739
Joined: Jan 01, 2009 7:03
Location: Australia

Re: My_basic interpreter

Postby BasicCoder2 » Jun 05, 2021 23:09

I confess I am ignorant of these "scripting" languages and their utility value. How is it different to a normal BASIC interpreter?

It is unclear what you want to do that is different to what is already available?

What sort of programming project would require a scripting language?
angros47
Posts: 1890
Joined: Jun 21, 2005 19:04

Re: My_basic interpreter

Postby angros47 » Jun 06, 2021 0:04

Actually, "scripting" means the purpose a language is created for. While "interpreter" means the method used by that language to work.

What I would like to do is: since my_basic has already been used to create some interesting programs, like https://paladin-t.github.io/b8/ and https://my-basic.github.io/awesome/, I'd like to try making something similar, using FreeBasic and OpenB3D, perhaps

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 4 guests