xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 9, 2011 13:05:04 GMT
Post by xcessive on Apr 9, 2011 13:05:04 GMT
This will be a dev log for a small project I am pursuing in my spare time. Basically it can be thought of as a programming language geared towards two things: being extremely simple and light-weight, and creating 2D games. I am not sure how much I will get done, or if I will even finish this. It seems like an interesting project however. I am creating the compiler and IDE in a combination of C, C++ tied together in a Blitzmax wrapper.
The language itself will at first be procedural/functional programming oriented. But I may add very simplistic OOP functionality using a type based system. The finished product will be a compiler and IDE for this language, and it will run on Mac (intel+powerPC) and Windows.
For now I want to complete a simple script interpreter for this language that will execute the tokenized compiled "machine code" as I will be using a tokenizing compiler, storing the instruction tree as an internal binary databank. I want to do this first as it will be by far the hardest part of this whole project.
Thus the current aims are:
- Create a basic system for reading and parsing - Math Parser - Expression Parser - Expression Parser with integer variables, float variables and boolean variables. - Ability to handle string expressions
- DECLAREINT token code - INPUTINTEGER token code - PRINTEXPRESSION token code - Output terminal and OpenGL graphics (2D)
- IF expression...ENDIF - Rest of token code execution - Tokenizing compiler that parses xBasic to token code and binds it to a run time. (This is half finished, I have the binding system ready for token code, but not a parser for the language) - A simple IDE.
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 9, 2011 13:05:47 GMT
Post by xcessive on Apr 9, 2011 13:05:47 GMT
Following is a working draft of the xBasic language I wish to implement;
LAST UPDATED 9/04/2011 Variables. //note all comments are in this form (// followed by the comment) String name = “value” int name = 10 float name = 0.023 bool name = expression Identifiers are case sensitive and can only contain letters and _'s. Datatypes: Int, float, string, boolean, reference (for arrays and assets like sound and graphics)
Built in variables: //none yet, will add more later
String functions. Identifier.toInt() //returns the int value of a string. It will return the first int value encountered. “a10dflfd200” will return 10. iD.toFloat() // Same as toInt, but for floats.
Maths. Normal parsing with nested brackets. Possible operations *; +,-,/,% Math functions: pow(num,power), sqrt(num).
Loops. While (expression) { //do something }
For (int I = 1 to 100) { //do something }
do { //something } while (expression)
Input: MouseX() // gets the current mouseX location MouseY() //gets the current mouseY location keyDown(key) //returns true if the specified key is currently down. mouseClick(button) //returns true if when the mouse button is clicked getKey() //returns the key currently being pressed input(variable) //gets input from the console
Decisions. if (expr) { //block of code }
if (expr) { //block of code }else { //another block }
case of varName { val: //code break val2: //code break default: //code }
Boolean Expressions. Can use ==, !=, !, >, >=, <=, =>, =<, <.
Output. print “str” //prints to the console
Graphics. window(w,h) //opens a new window w wide and h heigh render() //draws the rendered image to the screen and clears the buffer clear() //clears the buffer drawImage(img,x,y) //draws the image with the id img to the x,y location specified, anything drawn outside of the window will never get rendered or drawn. Images can be PNGs and JPGs. drawText(string,x,y) //draws the string to the given x,y locations anything drawn outside of the window will never get rendered or drawn.
Sound. Snd = loadSound(“path”) //loads the sound into snd from the path. playSound(snd) //plays the given sound, returns false if the sound doesnt exist.
Files. File = loadFile(“dir”) //loads the file into File readLine(file) //returns a line, and goes to the next one writeLine(file, string) //writes the string to the file, and moves down to the next line. closeFile(file) //closes the specified file
User Functions. Defined as follows: function returnType name(type var, type2 var2) { return blah }
Arrays. Int[15] ptr ptr[2] = 34 Functions: ptr.contains(var) ptr.sort(int asdOrDesc) ptr.search(varType key) ptr.clear() ptr.toString() ptr.expand(int size)
Generic functions. time() //returns system time
|
|
Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
xBasic
Apr 10, 2011 4:27:45 GMT
Post by Nick on Apr 10, 2011 4:27:45 GMT
Looks treacherous! Good luck, though you seem pretty capable of pulling off a job like this!
Also, are you going to post a download link so we can try it out?
|
|
Jordan
Elite Poster
[M:5000]
Posts: 286
|
xBasic
Apr 13, 2011 4:33:15 GMT
Post by Jordan on Apr 13, 2011 4:33:15 GMT
That's a challenging project. If you ever get the chance I'd like to play the with program (as well as the source if you feel like sharing).
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 15, 2011 2:30:57 GMT
Post by xcessive on Apr 15, 2011 2:30:57 GMT
I added the IF block today. Turned out to be quite a challenge..
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 15, 2011 7:19:16 GMT
Post by xcessive on Apr 15, 2011 7:19:16 GMT
I have run into what may be a problem. I implemented a while loop and used it to do a speed test. The results are not good. Not good at all.. Its taking ~3500 milliseconds to execute this code:
DECLAREINTEGER z [0] WHILE [z<10000] SETINTEGER z [z+1] WEND
I think the problem might be the massive number of function calls made by my execution loop.
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 15, 2011 10:54:37 GMT
Post by xcessive on Apr 15, 2011 10:54:37 GMT
I think for now I might just have to make a compiler for the tokenized code, and worry about optimizations and the xBasic language later. Thoughts?
|
|
Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
Post by Nick on Apr 16, 2011 4:56:40 GMT
I have run into what may be a problem. I implemented a while loop and used it to do a speed test. The results are not good. Not good at all.. Its taking ~3500 milliseconds to execute this code: DECLAREINTEGER z [0] WHILE [z<10000] SETINTEGER z [z+1] WEND I think the problem might be the massive number of function calls made by my execution loop. What was the integer???
|
|
Jordan
Elite Poster
[M:5000]
Posts: 286
|
xBasic
Apr 16, 2011 5:22:43 GMT
Post by Jordan on Apr 16, 2011 5:22:43 GMT
I think for now I might just have to make a compiler for the tokenized code, and worry about optimizations and the xBasic language later. Thoughts? That doesn't sound like a bad idea. There is a lot that you have to do so just getting one part working makes sense. Get the basic structure and then see how you can optimize it. I have run into what may be a problem. I implemented a while loop and used it to do a speed test. The results are not good. Not good at all.. Its taking ~3500 milliseconds to execute this code: DECLAREINTEGER z [0] WHILE [z<10000] SETINTEGER z [z+1] WEND I think the problem might be the massive number of function calls made by my execution loop. What was the integer??? He set it to zero. As you can see, he's placing what would normally go after the "=" sign in brackets, most likely because it's much easier to parse. int z = 0; while (z < 1000) z = z + 1;
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 16, 2011 6:03:22 GMT
Post by xcessive on Apr 16, 2011 6:03:22 GMT
I think for now I might just have to make a compiler for the tokenized code, and worry about optimizations and the xBasic language later. Thoughts? That doesn't sound like a bad idea. There is a lot that you have to do so just getting one part working makes sense. Get the basic structure and then see how you can optimize it. What was the integer??? He set it to zero. As you can see, he's placing what would normally go after the "=" sign in brackets, most likely because it's much easier to parse. int z = 0; while (z < 1000) z = z + 1;[/quote] Correct on all counts. I made some changes, and instead of using a list based map, I am now using a red-black tree based map. Its much faster for lookups and it sped up the code to about 1700 ms. Which is still too slow however. I think whats slowing me down is the fact I am using regex to find variables before I parse them. Which has insane complexity demands. I might just write my own variable parser that loops through the expression until it finds something that isn't a number or an operator and does the Map look up. It should be faster at least. I might also stop using my maths parser (which is slow as hell) and use muParser. Either that or re-write it. Also in other news I've ported almost all of the project to Blitzmax. Just because its easier to work with than C and it means I don't have to worry about graphics and audio drivers.
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 16, 2011 6:10:24 GMT
Post by xcessive on Apr 16, 2011 6:10:24 GMT
Update: Regex is definitely the culprit. I am going to have to recode my variable finder, it shouldn't be too hard, its basically a linear search.
I also Implemented muParser and made the code create less unnecessary objects - down to 950ms. It might soon be fast enough not to have to recode!
EDIT: down to about ~880ms which is probably fast enough considering this isnt truly compiled. It makes it comparable to PHP, which is acceptable.
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 16, 2011 10:24:35 GMT
Post by xcessive on Apr 16, 2011 10:24:35 GMT
Update: I have been doing some testing and it turns out of that 880 milliseconds, muParser contributes 790+ of them. I need to get a faster parser! Perhaps if I recoded my old one, but put the expression is reverse polish notation at compile time rather than at run time... hmm...
|
|
Cam
Administrator
[M:5000]
Posts: 6,381
|
xBasic
Apr 17, 2011 0:04:30 GMT
Post by Cam on Apr 17, 2011 0:04:30 GMT
That must be so hard.
|
|
Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
Post by Nick on Apr 17, 2011 2:17:39 GMT
I think for now I might just have to make a compiler for the tokenized code, and worry about optimizations and the xBasic language later. Thoughts? That doesn't sound like a bad idea. There is a lot that you have to do so just getting one part working makes sense. Get the basic structure and then see how you can optimize it. What was the integer??? He set it to zero. As you can see, he's placing what would normally go after the "=" sign in brackets, most likely because it's much easier to parse. int z = 0; while (z < 1000) z = z + 1;[/quote] Oh! Lol, my ipod hides stuff in brackets!
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 17, 2011 2:21:30 GMT
Post by xcessive on Apr 17, 2011 2:21:30 GMT
I just discovered a really odd bug.
IF statements don't work in WHILE loops. :S I might have to release a version of the interpreter for people to play with and find more of these bugs.
|
|
Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
Post by Nick on Apr 17, 2011 2:33:48 GMT
I just discovered a really odd bug. IF statements don't work in WHILE loops. :S I might have to release a version of the interpreter for people to play with and find more of these bugs. That would be cool! How big is your library?
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
xBasic
Apr 17, 2011 2:45:07 GMT
Post by xcessive on Apr 17, 2011 2:45:07 GMT
I just discovered a really odd bug. IF statements don't work in WHILE loops. :S I might have to release a version of the interpreter for people to play with and find more of these bugs. That would be cool! How big is your library? The command library? At the moment its pretty damn small, just the bare basics for a simple console app.
|
|