I have an idea for a program but I don't know if its possible.

I want to write a program that can read commands from a file.. For example, I've seen bots that can parse and read javascript for games and execute whatever is in the .java file..

How can I do this in c++ I want to read commands from a file and execute them.. Example:

Read MoveMouse(X, Y);... the client would SetCursorPos(X, Y);.

Possible or no?

Pretty much everything is possible in C++, it's a question of the amount of effort that you want to put in.

It's not entirely clear from you post what it is that you want to do, but it sounds like it could be quite a lot of work.

Reading commands from a file is not too difficult, you could define your own small scripting language and write some code to parse it and and some more code to do things based on the code that you parsed.

However, I don't think this is what you want to do. It sounds like you want to parse an existing language, like Javascript, and do things specified in the script. This sounds like you basically want to write your own Javascript engine, which is definitely a non-trivial task.

commented: Thank you. +5

If you want to support a small set of commands you can do so directly with a std::map< std::string, std::string > . Simply read in tokens and map them to appropriate commands. If you want to support something more complex, as ravenous suggests, you will have a bit more work to do.

The traditional mechanism for parsing languages is to work with a tool that generates parsers from a language spec (google terms: lex and yacc (the tool) or parser generator (the concept))

commented: Thank you +5

Ahh thank you guys.. this is actually a project that I assumed could take me at least a year or so.

I'll definitely look into what you guys have said. It's kinda both lol. I actually want to parse an existing language aka C++.. I used javascript as an example because it's the only example I could have thought of since I have never came across a c++ bot that parses a language.

I just spent the last 24 hours reading stack overflow, daniweb, etc, etc on parsers, lexers, etc to see how compilers do it.. I guess in short you can say I'm attempting to write an interpreter for c++?

I'm willing to put in the work though. If I have more questions, I'll be sure to check back and ask but thanks for now guys :D