Own Programming Language
Blitz3D Forums/Blitz3D Beginners Area/Own Programming Language
| ||
If we were to create our own programming language, how would we go about it? I have made this very simple (3 commands) compiler and want to know if it will ever make it out there. I call it a ZT Compiler.AppTitle "ZT COMPILER" a$=CommandLine$() If Left$(a$,5)="-ccas" Then filename$=Mid$(a$,7,Len(a$)) If filename$="" End EndIf Else End EndIf Global started=False file=OpenFile(filename$) If file=0 Error("Could not compile!") Else Repeat command$=ReadLine(file) If Eof(file) Error("DONE!") EndIf If command$<>"" Then If Left$(command$,7)="ADDline" Then therest$=Mid$(command$,8,Len(command$)) If Left$(therest$,2)="[[" Then kk$=Mid$(therest$,3,Len(therest$)) If Right$(kk$,2)="]]" txt$=Mid$(kk$,1,Len(kk$)-2) Print txt Else Error("Missing ]]!") Exit EndIf EndIf ElseIf Left$(command$,13)="[{ScreenRes}]" Then therest$=Mid$(command$,14,Len(command$)) location=Instr(therest$,"|") If location>0 width=Mid(therest$,1,location) height=Mid(therest$,location+1,Len(therest$)) Graphics width,height,32,2 started=True EndIf ElseIf command$="++QUIT" If started=True Then EndGraphics Exit ElseIf started=False Then Error("ScreenRes hasn't been initialized!") Exit EndIf EndIf EndIf Forever CloseFile file EndIf End Function Error(message$) api_MessageBox 0,message$,"ERROR",0 End Function The command line parms are : -ccas filename.zt The ZT source file: [{ScreenRes}]800|600 ADDline[[HEY EVERYBODY!!! THIS IS A TEST ON MY VERY]] ADDline[[NIFTY COMPILER THAT I MADE BY MYSELF!!!]] ++QUIT |
| ||
In what way is that a compiler? I've only skimmed the code, but it sure looks like an interpreter. |
| ||
>In what way is that a compiler? I've only skimmed the code, but it sure looks like an interpreter.< Whats the difference? When you compile the "compiler" part it will pretty much be like blitzcc.exe, won't it? All I have to do then is to create an IDE. |
| ||
A compiled program doesnt need the source to run, that is, is made into a runnable. Intepreted code on the other hand, the source needs to be present for the code to run. (At the simplest) |
| ||
So an interpreter just reads through the code and calls out what functions are needed and a compiler puts the code into EXE form? |
| ||
Hmm, i wonder if theres legal issues if you do this though, like using blitz command set masked behind your own language, i mean technicly no one would know, but still it seems safer to do it in C++ or somthing |
| ||
So an interpreter just reads through the code and calls out what functions are needed and a compiler puts the code into EXE form? Yep, also, an intepreter needs to be present when the code is run, but a compiler only needs to be present when the exe (or whatever), is created. |
| ||
Hmm, i wonder if theres legal issues if you do this though, like using blitz command set masked behind your own language, i mean technicly no one would know, but still it seems safer to do it in C++ or somthing But wouldn't there be legal issues if you do that also? Because you're using C++'s command set. |
| ||
C++ is an well i don't know the word for it, but nobody owns it so no legal issues As far as i know |
| ||
anyone got a link to the terms of use/EULA of blitz? |
| ||
Is this similar to how you write a scripting engine for a game? I've never used scripting but would imaging this is the way you would go about putting it in your game. |
| ||
An interpreter is a piece of software that reads in source code and executes the instructions there and then:- http://www.syntaxbomb.com/forum/index.php/topic,113.0.html No stand alone executable is created, and if the source code is to be used on another PC, the interpreter must go with it, but this isnt technically true, as you can hide that simple fact. I programmed a new rewrite/revision of the source code above that piggy backs the source code at the end of the interpreter and reads it in from there, this means that it can go anywhere, just like a normal exe. Because of EULA problems and what not, it wont be released... It was a proof on concept thing I did while playing! :) Interpreters and compilers share a lot of similar properties, the only difference is the back end, where a interpreter's back-end is the part that executes action in the source code, a compiler's back-end generates object code based on the source code. Thats how I describe a compiler, but then, compilers have grown to incorporate a linker. When a linker is involved, the code generating part might be named as the middle-end. A application than needs an interpreter executes slower than a compiled version of it. Dabz |
| ||
If you really want to write a compiler then use the right tool for the job, i.e. C or C++ not Blitz. |
| ||
Or Max, as the rewrite mentioned above is now in Max and it does a very good job of it too! :) Having OOP makes stuff a little easier:- The above code is part of the symbol table that handles constant values, variables and arrays... This is much more simple than the old Blitz way of programming. I currently havent included any scope information in my interpreter (which is usually handled, I think) by the symbol table... All variables and arrays are global. By the way, I love stuff like this! :) Dabz |
| ||
I would do what Max does and spit out assembly language rather than raw machine code... makes the task easier. A large part of the task is text parsing. I would definitely use Max over C. Bound to be easier. |