? Math Compiler ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
Contest results!

Math Compiler

Submitted
Updated
Author
ninjagnu
Public Key
8RNQ23CJ
Min. Compat.
All
Rating
1 vote
Description Compiles simple semicolon separated math expressions like this one, 1+1;into stack based SmileBASIC code like these: DIM S[32] PUSH S,1 PUSH S,1 R=POP(S) L=POP(S) PUSH S,L+R PRINT POP(S) I plan to expand this into a much larger fully featured compiler for a programming language. Instructions Change your active project to MATHC go to create programs with SmileBASIC in the main menu. Run this command in direct mode: EXEC "PRG1:COMPILER"The compiler will compile the code in IN and output SmileBASIC to OUT. If you wish to change the input to compiler you can edit the file named IN.
Categories
Keywords
7 Comment(s) snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself You may be interested in the shunting yard algorithm (if you aren't using it already.) Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies But if you use the shunting yard algorithm BE SURE that you mark a way for the output to know where a parentheses end. Otherwise you'll have a bug where a function's parameters fade into another function and it becomes a big mess trying to estimate how many arguments each function has But yes, use the Shunting Yard Algorithm, as it is much higher performance compared to an abstract syntax tree. ASTs should be used for Computer Algebra Systems only, cause they allow moving around operators and arguments to simplify If you have any questions message me snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself I used shunting yard to do something similar in JS, but I added functions by just bodging together prefix operators. There really isn't much difference between sin x and sin(x) so it worked okay. The consequence is that they only took one variable. Lumage Lumage Head Admin interesting ninjagnu ninjagnu This is the project I need a tree data structure for. The parser would return a populated tree data structure instead of emitting SmileBASIC. The parser would pass this tree to the type checker and the type checker would type check everything recursively with a DFS algorithm if it encounters a type error it will alert the user and stop. If no errors are encountered the type checker will pass the type checked tree on to the code generator etc. etc. Lumage Lumage Head Admin Right. If you do get that malloc/tree implementation, it would be neat if you could publish it as a separate library so other people can find it easily, too. ninjagnu ninjagnu Will do, I think I've got an idea on how things should work. Just need to get a working flow chart done on paper so I can visualize things.