If you're using C++, just use a map.
If you're using C++, just use a map.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
a what? never heard of maps before in C++....
anyways, i've got v1.00b finished now, i made a cool little demo that goes with it, please download it and tell me what you think i'm looking for feedback...........
Yeah, it's really cool to create your own programming language.
Actually I was thinking of implementing a similar library for Omicron.
I tested your compiler and code and it seemed to work fine.
One thing that is useful is named variables, only numbers can be a little too esoteric, especially since you're targeting newbies.
Hmm, actually ( and ) are quite useful in long expressions.5) Any command without parameters must NOT have any parenthesis....that should make logical sense, lol
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
Originally posted by jverkoey
a what? never heard of maps before in C++....A map<string,double> is perfect to store variables. I'm using that technique in Omicron.Code:#include <map> #include <iostream> #include <string> int main() { using namespace std; map<string,int> myMap; myMap["one"] = 1; myMap["two"] = 2; ... myMap["zero"] = 0; cout << "Type in a number (as text) "; string s; cin >> s; cout << "You typed in " << myMap[s]; }
Last edited by Sang-drax; 03-15-2003 at 06:04 AM.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
Cool stuff! I like the help file. This could turn into something pretty cool.
Are you going to add anything in where you can make loops? A while and for loop should be enough, but a do...while loop wouldn't be bad either.
ok..........hmmmmm...........thinking...........Originally posted by Sang-drax
A map<string,double> is perfect to store variables. I'm using that technique in Omicron.Code:#include <map> #include <iostream> #include <string> int main() { using namespace std; map<string,int> myMap; myMap["one"] = 1; myMap["two"] = 2; ... myMap["zero"] = 0; cout << "Type in a number (as text) "; string s; cin >> s; cout << "You typed in " << myMap[s]; }
ok
i think i have an idea
how's about, with the maps, if i do something like this:
i'll have mutliple maps, one for each type of variable (character arrays, float, and ints), so it'll probably be something like this:
map<char[40] [NUMVARS],int> integers;
map<char[40] [NUMVARS],float> floats;
map<char[40] [NUMVARS],char[1024]> chars;
-edit-
and 40 could possibly not the most amount of variables you could have, I could (theoretically) just resize it every time they got more than that..........
-end of edit-
oook, and that theoretically works (i'll need feedback on this, cuz i just found out about maps )
and then, once I have those declared, if I want to create a variable, I would do something like so:
@char <name>
@int <name>
@float <name>
where name would be the name of the variable
and then the engine would read that in from the file and see that it starts with an @ sign, and go in to variable declaration mode. It would then assign the name given to it to <mapname>[<charname]
ex: you declared a @char name; , the engine would read that in, and assign "name" to the first available slot on the map. then, if you wanted to assign something to the variable, you'd just do: @<name>=<value>; and that would assign <value> to the corresponding <name> spot on the map.......this is assuming that what I assumed is correct, lol
so, any input? i have NO idea as to whether or not this'll work....and it'll probably take me a while to implement (it took me about 2 hours just to implement the @<number> system, but I have to admit, that one IS kinda static....)
Last edited by jverkoey; 03-15-2003 at 01:08 PM.
wha? what I meant by that was that if you have a command that doesn't take any parameters, like Reset;, then you shouldn't PUT any parameters in it, so Reset("hey"); would return an error and the program would quit..........see what I mean?Originally posted by Sang-drax
Hmm, actually ( and ) are quite useful in long expressions. [/B]
err, and with the maps, I must be either A) missing something, or B) Visual Studio doesn't like maps.........because they aren't compiling (even though I included all the header files...)
I'm assuming there's probably a library i need, but I dont' know which one.......
-edit-
added the namespace thing (which i don't like using that much) to the file, and all of a sudden, 68 errors popped up, that's why i don't use it I'm assuming that you HAVE to use the namespace thing, but if I won't be able to program anything else because of it, i'm just gonna screw the map things...........
Last edited by jverkoey; 03-15-2003 at 12:46 PM.
Probably A), because Visual Studio likes maps. No library is needed, maps are part of C++.Originally posted by jverkoey
err, and with the maps, I must be either A) missing something, or B) Visual Studio doesn't like maps.........because they aren't compiling (even though I included all the header files...)
I'm assuming there's probably a library i need, but I dont' know which one.......
Remember to use correct headers, like <iostream> instead of <iostream.h>. Can you compile my example?Originally posted by jverkoey
added the namespace thing (which i don't like using that much) to the file, and all of a sudden, 68 errors popped up, that's why i don't use it I'm assuming that you HAVE to use the namespace thing, but if I won't be able to program anything else because of it, i'm just gonna screw the map things...........
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
well, thing is, i'm not using Dos console stuff, i'm using an API, so I don't even have the iostream.h header file, these are all the header files I have for my scripting engine:
#include <fstream.h>
#include <string.h>
#include <windows.h>
#include <ctype.h>
#include "map.h"
and map.h is a header i just created myself cuz i'm frustrated with the maps GRR
this is the map.h header file:
that all theoretically works, right now i'm putting it in to the engine.......Code:#define BOOLEAN 1 #define CHARACTER 2 #define FLOAT 3 #define INTEGER 4 class map { private: char name[100]; int type; bool bvalue; char cvalue[1024]; float fvalue; int ivalue; bool used; public: map(); void create(char* Name,int Type); bool createB(bool value); bool createC(char* value); bool createF(float value); bool createI(int value); }; map::map() { used=false; } void map::create(char* Name, int Type) { strcpy(name,Name); type=Type; used=true; } bool map::createB(bool value) { if(type==BOOLEAN) { bvalue=value; return true; } return false; } bool map::createC(char* value) { if(type==CHARACTER) { strcpy(cvalue,value); return true; } return false; } bool map::createF(float value) { if(type==FLOAT) { fvalue=value; return true; } return false; } bool map::createI(int value) { if(type==INTEGER) { ivalue=value; return true; } return false; }
-edit-
ok, i've put it in the engine, and now I can create variables....just working on all the debugging for that, then i'm going to make it so you can use the variables
Last edited by jverkoey; 03-15-2003 at 02:27 PM.
That should read (or else the map header might not work):Originally posted by jverkoey
well, thing is, i'm not using Dos console stuff, i'm using an API, so I don't even have the iostream.h header file, these are all the header files I have for my scripting engine:
#include <fstream.h>
#include <string.h>
#include <windows.h>
#include <ctype.h>
#include "map.h"
If you want different data types, I suggest creating a "datatype" class:Code:#include <fstream> #include <cstring> #include <windows.h> #include <ctype.h> using namespace std; #include "map.h"
Code:class DataType { enum Type {Int,String,Float}; int intValue; string stringValue; float floatValue; ... public: DataType(string s); DataType(int i); ... string GetString(); ... }; //This map holds all your variables std::map<string,DataType> variables;
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
baaha, yes, i forgot about overloading functions, that'll make my map.h header file easier to work with. All i'll need now is just an assign and create function, and just overload 'em with each of the variable types....
but yah, right now i've got it so you can declare your own variables, and you can create an unlimited amount (until memory runs out ) and i'm halfway through making it so you can add/subtract/multiply, yadda each of the variables. I'm only going to have 4 types of variables, because I don't see the need in having any more than that.....float int char bool and that should be all anyone'll ever need.
hoping to get all of the variable stuff done tonight, then tomorrow I'll add a bunch more commands to the language....and maybe even think of adding "header files" so that people can define their own commands....
whooohoo, my 100th post!
*sniff* i knew, *sniff* this day would come, *sniff* i am now *sniff* a senior!!
What a waste of a post. :POriginally posted by jverkoey
whooohoo, my 100th post!
*sniff* i knew, *sniff* this day would come, *sniff* i am now *sniff* a senior!!
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
well, hey, i was sitting there, staring at the fact that i had 99 posts...I didn't have anywhere else to post, and I knew i'd be flamed if i started a whole new topic on my 100th post, so i just replied to this forum......lol seriously, it was like it was calling me to post the 100th post.....and i wanted to be a senior