0

I have developed a frame work for a scripting language and I am trying to make a compiler for it to output onto a certain file a custom Hex code to be read by an interpreter for applications such as games and movies. The interpreter will read the hex and perform operations via loops and pretty much do the hard work for me. But I need a way to compile the strings of text into my custom hexadecimal. Here is an example of my compiler.

#include <iostream>
#include <string>
#include <Windows.h>
#include <wincon.h>
#include <fstream>;
using namespace std;

int main(){
    char egScriptpath[999];
    char path[999];
    char title[999];
    ifstream readfile;
    ofstream myfile;
    int optn;

    cout << "Enter the path where your *.egSCRIPT file is: " << endl;
    cin.getline(egScriptpath,999);

    cout << "Enter your path where you want to compile your *.egSCRIPT file: " << endl;
    cin.getline(path,999);

    cout << "Enter your title for your program: ";
    cin.getline(title,999);

    cout << endl << "Enter for your option of file extention:" <<  endl;
    cout << "   Enter 1 for .egGame :" << endl;
    cout << "   Enter 2 for .egMovie: ";
    cin >> optn;

    if(optn==1){
        readfile.open((string)egScriptpath);
        ofstream egMovieFile((string)path+"\\"+(string)title+".egGame");
        myfile.open((string)path+"\\"+(string)title+".egGame");
        while(!readfile.eof()){
            if(readfile.getline("validated()",1)){
              myfile << "              \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
                        "               \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
                        "                \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
                        "                ////////////////\n"
                        "               ////////////////\n"
                        "              ||||||||||||||||\n"
                        "              ||||||||||||||||\n"
                        "              ||||||||||||||||\n"
                        "              \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n"
                        "              \2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\n";
            }
        }
        myfile.close();
        readfile.close();

    }else if(optn==2){
        readfile.open((string)egScriptpath);
        ofstream egGameFile((string)path+"\\"+(string)title+".egMovie");
        myfile.open((string)path+"\\"+(string)title+".egMovie");

        while(!readfile.eof()){
            if(readfile.getline("validated()",1)){
            myfile << "              \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
                      "               \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
                      "                \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"
                      "                ////////////////\n"
                      "               ////////////////\n"
                      "              ||||||||||||||||\n"
                      "              ||||||||||||||||\n"
                      "              ||||||||||||||||\n"
                      "              \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n"
                      "              \2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\n";
            }
        }
        myfile.close();
        readfile.close();
    }

    cout << "Compile complete" << endl;
    system("pause");

    return 0;
}

So what I want to do is in the if statement where it says if(readfile.getline("validated()",1)){} I want it to write onto the "myfile" ofstream variable the text that you can see just for an example. I hope I am clear on what I am saying. If the compiler reads "validated()" on my script file, then it will write the "hexadecimal" code onto the new file with the variable of "myfile" which will in return be interpreted by the interpreter for applications such as games and movies. Thanks if you know what is wrong and why it is not writing the hex code onto the new file that it makes.

1 Answer 1

2

Looks like your problem is located here:

if(readfile.getline("validated()",1)){

Sincerely, I don't even know why the compiller allows you to do so, but I would like to suggest to you the following change:

instead of:

while(!readfile.eof()){
    if(readfile.getline("validated()",1)){

use this one:

std::string buffer;
while (std::getline(readfile, buffer, '\n')){
    if (buffer == "validated()")

also, since you are using C++, instead of use arrays of char, you should relly more on std::string class.

Sign up to request clarification or add additional context in comments.

1 Comment

I know that is where the error is, but I cant find out what is wrong with it. Do you know?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.