Write a compiler. Some possibility?

Everything else that doesn't fall into one of the other PB categories.
2Player
New User
New User
Posts: 4
Joined: Sat Dec 17, 2005 2:01 am

Write a compiler. Some possibility?

Post by 2Player »

I'm thinking. Has any possibility of to write a new programming language and a compiler, using the PureBasic?

It's possible or I'm Crazy?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

You bet, with compilers written in VB, you can pretty easily convert it over to PB ... reference: http://www.kidev.com
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Sure it's possible, I've got one in front of me (not usable for anything yet but has a lot of skeleton like expression with many operators and constructs for conditional execution), but I don't want to give you the source. :wink:
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

I don't know about compilers, but what about interpreters? It would require a runtime, and could be used as a base
for a scripting language i suppose.

There's quite a few sources around, and I think it would be nice to have one of them translated to PureBasic.
venom
User
User
Posts: 56
Joined: Fri Jul 25, 2003 1:54 pm
Location: Australia

Post by venom »

I'm kind of working on a virtual machine and assembler thats so far been written in PureBasic, it currently can do calculations and pointer handling.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

To clarify what I said, here's a working Basic Interpreter, submitted to an obfuscated code contest years ago written
in ANSI C. If there are any C programmers here, the first step is to submit it to a preprocessor. :wink:

Any taker's? At least about running it through a preprocessor and postiing the result, or PM it to me.

Code: Select all

#define O(b,f,u,s,c,a)b(){int o=f();switch(*p++){X u:_ o s b();X c:_ o a b();
default:p--;_ o;}}
#define t(e,d,_,C)X e:f=fopen(B+d,_);C;fclose(f)
#define U(y,z)while(p=Q(s,y))*p++=z,*p=' '
#define N for(i=0;i<11*R;i++)m[i]&&
#define I "%d %s\n",i,m[i]
#define X ;break;case
#define _ return
#define R 999
typedef char*A;int*C,E[R],L[R],M[R],P[R],l,i,j;char B[R],F[2];A m[12*R],malloc
(),p,q,x,y,z,s,d,f,fopen();A Q(s,o)A s,o;{for(x=s;*x;x++){for(y=x,z=o;*z&&*y==
*z;y++)z++;if(z>o&&!*z)_ x;}_	0;}main(){m[11*R]="E";while(puts("Ok"),gets(B)
)switch(*B){X'R':C=E;l=1;for(i=0;i<R;P[i++]=0);while(l){while(!(s=m[l]))l++;if
(!Q(s,"\"")){U("<>",'#');U("<=",'$');U(">=",'!');}d=B;while(*F=*s){*s=='"'&&j
++;if(j&1||!Q(" \t",F))*d++=*s;s++;}*d--=j=0;if(B[1]!='=')switch(*B){X'E':l=-1
X'R':B[2]!='M'&&(l=*--C)X'I':B[1]=='N'?gets(p=B),P[*d]=S():(*(q=Q(B,"TH"))=0,p
=B+2,S()&&(p=q+4,l=S()-1))X'P':B[5]=='"'?*d=0,puts(B+6):(p=B+5,printf("%d\n",S
()))X'G':p=B+4,B[2]=='S'&&(*C++=l,p++),l=S()-1 X'F':*(q=Q(B,"TO"))=0;p=B+5;P[i
=B[3]]=S();p=q+2;M[i]=S();L[i]=l X'N':++P[*d]<=M[*d]&&(l=L[*d]);}else p=B+2,P[
*B]=S();l++;}X'L':N printf(I)X'N':N free(m[i]),m[i]=0	X'B':_ 0 t('S',5,"w",N
fprintf(f,I))t('O',4,"r",while(fgets(B,R,f))(*Q(B,"\n")=0,G()))X 0:default:G()
;}_ 0;}G(){l=atoi(B);m[l]&&free(m[l]);(p=Q(B," "))?strcpy(m[l]=malloc(strlen(p
)),p+1):(m[l]=0,0);}O(S,J,'=',==,'#',!=)O(J,K,'<',<,'>',>)O(K,V,'$',<=,'!',>=)
O(V,W,'+',+,'-',-)O(W,Y,'*',*,'/',/)Y(){int o;_*p=='-'?p++,-Y():*p>='0'&&*p<=
'9'?strtol(p,&p,0):*p=='('?p++,o=S(),p++,o:P[*p++];}
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Interpreters and virtual machines are all crap. They're not fast enough. Sure, you can't expect an interpreter to be fast. Is that an excuse? I sent you a Fiat instead of a Lamborghini you ordered so don't expect it to be fast?

By the way, I can make a working Basic interpreter too (not as obfuscated), but who wants an interpreter?
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

but who wants an interpreter?


I do, and I also decides if it's fast enough for my use, not you. :wink:
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

Trond wrote:Interpreters and virtual machines are all crap. They're not fast enough. Sure, you can't expect an interpreter to be fast. Is that an excuse? I sent you a Fiat instead of a Lamborghini you ordered so don't expect it to be fast?

By the way, I can make a working Basic interpreter too (not as obfuscated), but who wants an interpreter?
I disagree with you, vms are not always slow. Depending on how much preprocessing is done, they can be very fast.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Trond wrote:Interpreters and virtual machines are all crap. They're not fast enough. Sure, you can't expect an interpreter to be fast. Is that an excuse? I sent you a Fiat instead of a Lamborghini you ordered so don't expect it to be fast?

By the way, I can make a working Basic interpreter too (not as obfuscated), but who wants an interpreter?
heh i bet you. Java IS fast. VERY fast!
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

But NetBeans IDE is so slow I hated to use it so much that I quit Java but I think this is because Java uses this wierd non standard Windowsystem.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Downloading
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

NetBeans uses Swing in which each gadget is effectively hand-drawn. This is slower but fits in with Sun's "write once, run anywhere" mantra because it is independent of the OS it is running on. Another graphical interface library is SWT, as used by Eclipse, which acts as a wrapper around the native OS GUI routines, just like PB does and is thus faster and feels more "natural". On the downside this approach requires updating the library for each OS it is to run on. It is up to the author what they use.
Mat
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

I'm writing an interpreter atm. It's called 'Spectacle', there's some (PureBasic) source floating about on the forums - but it's quite old now. Have a look for it.

I don't think it's that slow!
~I see one problem with your reasoning: the fact is thats not a chicken~
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

MrMat wrote:NetBeans uses Swing in which each gadget is effectively hand-drawn. This is slower but fits in with Sun's "write once, run anywhere" mantra because it is independent of the OS it is running on. Another graphical interface library is SWT, as used by Eclipse, which acts as a wrapper around the native OS GUI routines, just like PB does as is thus faster and feels more "natural". On the downside this approach requires updating the library for each OS it is to run on. It is up to the author what they use.
Wise words, mr. maD

however it runs quite good here, actually.
5 seconds startup isnt too bad.
Post Reply