Author Topic: Making a Basic interpreter  (Read 6019 times)

Emeka

  • Guest
Making a Basic interpreter
« on: August 19, 2015, 03:18:35 PM »
Hello All,

In my attempt to learn C language and at same time understand what goes on behind the surface, I created(or attempted to create) CBasic. It is still a work-in-progress. Not really clean and may not be for all. However, I encourage you to experiment and also contribute in making it something useful and standard. I work on it during my free time and I hope to continue to work on it as time permits.

It is written off C language.

https://github.com/janus/CBasic

Regards, \Janus
« Last Edit: August 19, 2015, 04:32:50 PM by ijanus »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Making a Basic interpreter
« Reply #1 on: August 19, 2015, 05:34:49 PM »
Small world.

Have you seen the C BASIC define wrapper I did? AIR did an enhanced version for C++.

C BASIC - BitBucket Repository

C BASIC is now a Script BASIC ext. module standard as the language is already heavily done in macros and defines. (extreme brutality if looking at it raw)

If I find some time, I'll convert your CBASIC to my C BASIC;D 

« Last Edit: August 19, 2015, 05:40:59 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Making a Basic interpreter
« Reply #2 on: August 20, 2015, 12:21:57 AM »
Janus,

I gave your CBASIC interpreter a try under Ubuntu 64 bit Linux. Here are my results.


jrs@laptop:~/c_code/cbasic$ gcc cbasic.c -o cbasic
cbasic.c: In function ‘cerror’:
cbasic.c:77:9: warning: format not a string literal and no format arguments [-Wformat-security]
         printf(message);
         ^
cbasic.c: In function ‘exec’:
cbasic.c:1017:13: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
             gets(buf);
             ^
cbasic.c: In function ‘parser’:
cbasic.c:1087:22: warning: format not a string literal and no format arguments [-Wformat-security]
                      printf(name);
                      ^
cbasic.c:1186:17: warning: format not a string literal and no format arguments [-Wformat-security]
                 printf(currenttoken->text);
                 ^
cbasic.c: In function ‘main’:
cbasic.c:1476:9: warning: format not a string literal and no format arguments [-Wformat-security]
         printf(lhead->text);
         ^
/tmp/cc7UVBP4.o: In function `exec':
cbasic.c:(.text+0x16ee): warning: the `gets' function is dangerous and should not be used.
jrs@laptop:~/c_code/cbasic$ ./cbasic
*

footap
0empty head
=tap
5empty head
(tap
7empty head
314159tap
1empty head
*tap
6empty head
10tap
1empty head
)tap
8empty head
-tap
6empty head
3000000tap
1empty head
DIMtap
0empty head
Atap
0empty head
(tap
7empty head
17tap
1empty head
)tap
8empty head
printtap
0empty head
footap
0empty head
tintap
0empty head
=tap
5empty head
3tap
1empty head
iftap
0empty head
tintap
0empty head
>tap
6empty head
tintap
0empty head
thentap
0empty head
fintap
0empty head
printtap
0empty head
footap
0empty head
inputtap
0empty head
guesstap
0empty head
printtap
0empty head
footap
0empty head
/tap
6empty head
guesstap
0empty head
fintap
3empty head
printtap
0empty head
Well Donetap
2empty head
printtap
0empty head
tintap
0
assign statement
A
array statement

print statement77

assign statement

If statement

print statement77

input statement

print statement77

print statement77

print statement77

141590.000000

141590.000000

user input>>print 1+1
ERROR--Don't mix up typesjrs@laptop:~/c_code/cbasic$


Emeka

  • Guest
Re: Making a Basic interpreter
« Reply #3 on: August 20, 2015, 02:26:48 AM »
Thanks .. I will look into what caused that. Just a minute please

Emeka

  • Guest
Re: Making a Basic interpreter
« Reply #4 on: August 21, 2015, 12:29:48 AM »
Please read the instruction .... I guess it runs are example already.. and that print out is part of the code already run ... it currently does not accept normal input the way the usual way

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Making a Basic interpreter
« Reply #5 on: August 21, 2015, 03:19:44 AM »
Sorry Janus but this is way to early for anyone to be playing with.

I'll take another look when you get rid of the debug info and can read the BASIC script from a file.