什么是程序接收信号sigsegv分段错误?

问题描述

我正在从事一个涉及创建非常简单的编译器的项目。我目前有2个版本的代码。两者均无法正常工作,但凌乱的凌乱的声音比组织良好的凌乱的声音要远得多。两者都将包括在内,以及我用于测试的文件

我尝试在dev-c ++中使用调试功能,但一点都不了解。我所知道的是它返回“程序收到信号sigsegv分段错误

任何帮助,将不胜感激。

代码段是完整的第一个版本,太难阅读了,我加入它的唯一原因是因为它可与第二个版本进行比较。

#include<iostream>
#include<array>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<typeinfo>
#include<ctype.h>
using namespace std;

vector <char> spacer(string &input) {
    vector <char> var;
    for(int i = 0; i < input.size(); i++) {
        var.push_back(input[i]);
        var.push_back(' ');
    }
    return var;
}



string ifHandler(vector<string> &com,array <string,100> &SML,int &InstPtr,int (&gotoPlace)[100] 
[2],int &gotoCtr,string dataTable[300][3],int &datCtr) {
    //string con=to_string(com[2]);
    //stringstream(com[1])>>con;
    vector<char> condition=spacer(com[2]);
    int caser;
    int loc;
    for (int i = 0; i < condition.size(); i++) {
        if (condition[i] == '!') {
            loc=i;
            caser = 1;  
            break;
        }
        else if(condition[i] == '=') {
            loc=i;
            caser = 2;
            break;
        }
        else if(condition[i] == '<') {
            loc=i;
            if(condition[i + 2] == '=') {
                caser = 5;
            }
            else {
                caser = 3;
            }
            break;
        }
        else if(condition[i] == '>') {
            loc=i;
            if (condition[i + 2] == '=') {
                caser = 6;
            }
            else {
                caser = 4;
            }
            break;
        }
     }
     switch(caser) {
        case 1:
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc-2]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="20"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="200"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc+4]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="31"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="310"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            if(com[4]<com[0]){
                for(int it=0;it<300;it++){
                    if (dataTable[it][2]==com[4]){
                        if(dataTable[it][2].size()>1){
                            SML[InstPtr]="42"+dataTable[it][2];
                        }else{
                            SML[InstPtr]="420"+dataTable[it][2];
                        }
                        InstPtr++;
                    }
                }
            }else{
                SML[InstPtr]="42";
                stringstream(com[4])>>gotoPlace[gotoCtr][0];
                gotoPlace[gotoCtr][1]=InstPtr;
                gotoCtr++;
                InstPtr++;
            }
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc+4]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="20"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="200"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc-2]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="31"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="310"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            if(com[4]<com[0]){
                for(int it=0;it<300;it++){
                    if (dataTable[it][2]==com[4]){
                        if(dataTable[it][2].size()>1){
                        SML[InstPtr]="42"+dataTable[it][2];
                        }else{
                            SML[InstPtr]="420"+dataTable[it][2];
                        }
                        InstPtr++;
                    }
                }
            }else{
                SML[InstPtr]="42";
                stringstream(com[4])>>gotoPlace[gotoCtr][0];
                gotoPlace[gotoCtr][1]=InstPtr;
                gotoCtr++;
                InstPtr++;
            }
            break;
        case 2:
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc-2]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="20"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="200"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc+4]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="31"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="310"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            if(com[4]<com[0]){
                for(int it=0;it<300;it++){
                    if (dataTable[it][2]==com[4]){
                        if(dataTable[it][2].size()>1){
                            SML[InstPtr]="42"+dataTable[it][2];
                        }else{
                            SML[InstPtr]="420"+dataTable[it][2];
                        }
                        InstPtr++;
                    }
                }
            }else{
                SML[InstPtr]="42";
                stringstream(com[4])>>gotoPlace[gotoCtr][0];
                gotoPlace[gotoCtr][1]=InstPtr;
                gotoCtr++;
                InstPtr++;
            }
            break;
        case 3:
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc-2]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="20"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="200"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc+2]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="31"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="310"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            if(com[4]<com[0]){
                for(int it=0;it<300;it++){
                    if (dataTable[it][2]==com[4]){
                        if(dataTable[it][2].size()>1){
                            SML[InstPtr]="42"+dataTable[it][2];
                        }else{
                            SML[InstPtr]="420"+dataTable[it][2];
                        }
                        InstPtr++;
                    }
                }
            }else{
                SML[InstPtr]="42";
                stringstream(com[4])>>gotoPlace[gotoCtr][0];
                gotoPlace[gotoCtr][1]=InstPtr;
                gotoCtr++;
                InstPtr++;
            }
            break;
        case 4:
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc+2]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="20"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="200"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc-2]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="31"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="310"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            if(com[4]<com[0]){
                for(int it=0;it<300;it++){
                    if (dataTable[it][2]==com[4]){
                        if(dataTable[it][2].size()>1){
                            SML[InstPtr]="42"+dataTable[it][2];
                        }else{
                            SML[InstPtr]="420"+dataTable[it][2];
                        }
                        InstPtr++;
                    }
                }
            }else{
                SML[InstPtr]="42";
                stringstream(com[4])>>gotoPlace[gotoCtr][0];
                gotoPlace[gotoCtr][1]=InstPtr;
                gotoCtr++;
                InstPtr++;
            }
            break;
        case 5:
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc-2]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="20"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="200"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc+4]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="31"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="310"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            if(com[4]<com[0]){
                for(int it=0;it<300;it++){
                    if (dataTable[it][2]==com[4]){
                        if(dataTable[it][2].size()>1){
                            SML[InstPtr]="41"+dataTable[it][2];
                        }else{
                            SML[InstPtr]="410"+dataTable[it][2];
                        }
                        InstPtr++;
                    }
                }
            }else{
                SML[InstPtr]="41";
                stringstream(com[4])>>gotoPlace[gotoCtr][0];
                gotoPlace[gotoCtr][1]=InstPtr;
                gotoCtr++;
                InstPtr++;
            }
            if(com[4]<com[0]){
                for(int it=0;it<300;it++){
                    if (dataTable[it][2]==com[4]){
                        if(dataTable[it][2].size()>1){
                            SML[InstPtr]="42"+dataTable[it][2];
                        }else{
                            SML[InstPtr]="420"+dataTable[it][2];
                        }
                        InstPtr++;
                    }
                }
            }else{
                SML[InstPtr]="42";
                stringstream(com[4])>>gotoPlace[gotoCtr][0];
                gotoPlace[gotoCtr][1]=InstPtr;
                gotoCtr++;
                InstPtr++;
            }
            break;
        case 6:
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc+4]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="20"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="200"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            for(int it=0;it<300;it++){
                if(dataTable[it][0][0]==condition[loc-2]){
                    if(dataTable[it][2].size()>1){
                        SML[InstPtr]="31"+dataTable[it][2];
                    }else{
                        SML[InstPtr]="310"+dataTable[it][2];
                    }
                    InstPtr++;
                    break;
                }
            }
            if(com[4]<com[0]){
                for(int it=0;it<300;it++){
                    if (dataTable[it][2]==com[4]){
                        if(dataTable[it][2].size()>1){
                            SML[InstPtr]="41"+dataTable[it][2];
                        }else{
                            SML[InstPtr]="410"+dataTable[it][2];
                        }
                        InstPtr++;
                    }
                }
            }else{
                SML[InstPtr]="41";
                stringstream(com[4])>>gotoPlace[gotoCtr][0];
                gotoPlace[gotoCtr][1]=InstPtr;
                gotoCtr++;
                InstPtr++;
            }
            if(com[4]<com[0]){
                for(int it=0;it<300;it++){
                    if (dataTable[it][2]==com[4]){
                        if(dataTable[it][2].size()>1){
                            SML[InstPtr]="42"+dataTable[it][2];
                        }else{
                            SML[InstPtr]="420"+dataTable[it][2];
                        }
                        InstPtr++;
                    }
                }
            }else{
                SML[InstPtr]="42";
                stringstream(com[4])>>gotoPlace[gotoCtr][0];
                gotoPlace[gotoCtr][1]=InstPtr;
                gotoCtr++;
                InstPtr++;
            }
            break;
    }
    cout<<"Not struggling with if"<<endl;
}



string compressor(string &input) { // we can pass a substring of the string to the method if we dont        want the whole thing to be compressed
    for (int i = 0; i < input.size(); i++) {
        if (input[i] == ' ') {
            input.erase(i,1); // erases the space at index i
        }
    }
    return input;
}



int gotoFix(array<string,string (&datTab)[300][3],int (&got)[100][2]){
    for(int i=0; i<sizeof(got);i++){
        for(int it=0; it<sizeof(datTab);it++){
            if(datTab[it][0]==""){
                break;
            }
            if(datTab[it][0]==to_string(got[i][0])){
                if(datTab[it][2].size()<2){
                    SML[got[i][1]]+="0"+datTab[it][2];
                }else{
                    SML[got[i][1]]+=datTab[it][2];
                }
            }
        }
    }
}



vector<string> parse(string &line){   //Takes the line and separates all of it's elements
    string parser="";                 //A placeholder string used to store each word into a vector
    vector<string> parsed;            //The Return vector
    char space = ' ';                
    for(int i=0; i<line.size();i++){   //If the character is not a space it is added into parser
        if (line[i]!=space){
            parser+=line[i];
        }else {                        //If the character is a space,parser is added into the vector,and is then reset
            parsed.push_back(parser);
            parser="";
        }
        if(i==(line.size()-1)){        //When the last character is reached,parser needs to be added into the vector,or it would be left out entirely
            parsed.push_back(parser);
        }
    }
    return parsed;
}



int registry(string command,int &DataCtr,int &symCtr){     //Used to determine what command is being worked with
    int literal;
    if(command==""){      //Absences are just here for blank lines
        return 5;
    }else if(command=="rem"){   //If command is rem,we stop the loop because content after rem is useless to the assembler
        return 5;
    }else if(command=="input"){   //If command is input,sets up the assembler command
        symCtr++;
        return 0;
    } else if(command=="print"){   //If command is print,sets up the assembler command
        return 1;
    }else if(command=="end"){   //If primary command is end,completely stops processing data
        return 2;
    }else if(command=="goto"){
        return 6;
    }
    else if(command=="if"){
        
        return 7;
    }else{
        if(isdigit(command[0])){   //Checks for a literal
            return 3;
        }else{   //if no literal is found,just establishes a variable
            return 4;
        }
    }
}



int maneuver(string (&arr)[300][3],vector<string> &com,int &line,int &DatCtr,array<string,int (&got)[100][2],int &gotoCtr){   //This creates the data table
    if (com[0]==""){
        return 1;
    }
    cout<<com[1]<<endl;
    line++;
    arr[line][0]=com[0];   //Processes line numbers
    arr[line][1]="L";
    arr[line][2]=to_string(InstPtr);
    for(int i=1;i<com.size();i++){     //This passes each part of the vector the function was passed to the registry for processing
        int retStat=registry(com[i],DatCtr,InstPtr,line);
        switch(retStat){
            case 0: 
                cout<<"input"<<endl;
                SML[InstPtr]="10"+to_string(DatCtr);
                InstPtr++;
                break;
            case 1:
                for(i=0;i<300;i++){
                    if(com[2]==arr[i][0]){
                        SML[InstPtr]="11"+arr[i][2];
                        i=300;
                    }
                }
                InstPtr++;
                break;
            case 2:
                cout<<"end"<<endl;
                SML[InstPtr]="4300";
                InstPtr++;
                i=com.size();
                break;
            case 3:
                cout<<"literal"<<endl;
                arr[line][0]=com[i];
                arr[line][1]="N";
                arr[line][2]=to_string(DatCtr);
                DatCtr--;
                break;
            case 4:
                cout<<"variable"<<endl;
                arr[line][0]=com[i];
                arr[line][1]="V";
                arr[line][2]=to_string(DatCtr);
                DatCtr--;
                break;
            case 5:
                cout<<"empty"<<endl;
                return 0;
            case 6:
                cout<<"goto"<<endl;
                if(com[0]<com[2]){
                    SML[InstPtr]="40";
                    stringstream(com[2])>>got[gotoCtr][0];
                    got[gotoCtr][1]=InstPtr;
                    gotoCtr++;
                }else{
                    for(i=0;i<300;i++){
                        if(com[2]==arr[i][0]){
                            if(arr[i][2].size()==1){
                                SML[InstPtr]="400"+arr[i][2];
                                i=300;
                            }else{
                                SML[InstPtr]="40"+arr[i][2];
                                i=300;
                            }
                        }
                    }   
                }
                InstPtr++;
                i=com.size();
                break;
            case 7:
                cout<<"if"<<endl;
                ifHandler(com,SML,got,gotoCtr,arr,DatCtr);
                cout<<"Made it through the if handler"<<endl;
                i=com.size();
                break;
        }
    }   
}



int main(){                  
    int currentDataCtr=99;   //Position for storing data
    int currentInstPtr=0;    //Position for storing commands
    int currentSymCtr=0;     //Position in the symbol table
    int gotoPlace[100][2]={0};
    int gotoCtr=0;
    array<string,100> SML;
    string baseCommand;
    string name;
    cout<<"Please enter the name of the file you would like compiled,\nnote it must be in the same folder as this program. (Example: test.txt)"<<endl;
    getline(cin,name);
    string ofile;
    cout<<"\nPlease enter the name of the file you would like the symbol table entered into,\nnote it will be in the same folder as the program. (Example: out.txt)"<<endl;
    getline(cin,ofile);
    string mfile;
    cout<<"\n Please enter the name of hte file you would like the machine code stored in,\nnote it will be in the same folder as the program. (Example: SMLCode.txt)"<<endl;
    getline(cin,mfile);
    ifstream baseFile(name);   //opens the file
    string dataTable[300][3];  //creates the data table (which is arbitrarily sized)
    dataTable[0][0]="Symbol";  //These 3 just create titles because titles are nice
    dataTable[0][1]="Type";
    dataTable[0][2]="Location";
    ofstream machFile(mfile);  //creates the outfile for the machine code
    while(getline(baseFile,baseCommand)){   //Pulls the lines from the infile and performs all methods on it
        vector<string> command=parse(baseCommand);
        cout<<command[1]<<endl;
        int condition=maneuver(dataTable,command,currentSymCtr,currentDataCtr,currentInstPtr,gotoPlace,gotoCtr);
        if (currentDataCtr<=currentInstPtr){  //Checks to make sure data and commands dont ovelap
            cout<<"This code is too long,and is running into issues of overlapping in memory."<<endl;
            exit(EXIT_FAILURE);
        }
        if(condition==1){  //Handles end
            break;
        }
    }
    baseFile.close();
    ofstream outFile(ofile);// all of this just prints the data table into a file
    outFile<<dataTable[0][0]<<" "<<dataTable[0][1]<<" "<<dataTable[0][2]<<endl;
    for (int i=1;i<=currentSymCtr;i++){
        for(int it=0;it<3;it++){
            outFile<<endl;
        }
    }
    gotoFix(SML,dataTable,gotoPlace);
    for (int i=0;i<currentInstPtr;i++){
        machFile<<SML[i]<<endl;
    }
    machFile.close();
    outFile.close();
    return 0;
}

下面包括第二个修订版,这是我希望继续使用的第二个修订版,但是它的效果不如第一个。但是它更短,更容易阅读。

#include<iostream>
#include<array>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<typeinfo>
#include<ctype.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;




//Parse lines to create commands
vector<string> parse(string &line){   //Takes the line and separates all of it's elements
    string parser="";                 //A placeholder string used to store each word into a vector
    vector<string> parsed;            //The Return vector
    char space = ' ';                
    for(int i=0; i<line.size();i++){   //If the character is not a space it is added into parser
        if (line[i]!=space){
            parser+=line[i];
        }else {                        //If the character is a space,or it would be left out entirely
            parsed.push_back(parser);
        }
    }
    return parsed;
}





//Command to parse conditions (and maybe math one day)
vector <char> spacer(string &input) {
    vector <char> var;
    for(int i = 0; i < input.size(); i++) {
        var.push_back(input[i]);
        var.push_back(' ');
    }
    return var;
}




//Performs gotos
int gotos(int gotoNum,int type,int (&gotoArr)[100][2],int lineNum,string (&dataTable)[300][3]){
    if(lineNum<gotoNum){
        SML[InstPtr]=to_string(type);
        gotoArr[gotoCtr][0]=gotoNum;
        gotoArr[gotoCtr][1]=InstPtr;
        gotoCtr++;
    }else{
        for(int i=0;i<300;i++){
            if(to_string(gotoNum)==dataTable[i][0]){
                if(dataTable[i][2].size()==1){
                    SML[InstPtr]=to_string(type)+"0"+dataTable[i][2];
                    i=300;
                }else{
                    SML[InstPtr]=to_string(type)+dataTable[i][2];
                    i=300;
                }
            }
        }   
    }
    InstPtr++;
}





//Performs conditional statements for the sml creater
int condi(array<string,string (&dataTable)[300][3],string item,string type){
    for(int it=0;it<300;it++){
        if(dataTable[it][0]==item){
            if(dataTable[it][2].size()>1){
                SML[InstPtr]=type+dataTable[it][2];
            }else{
                SML[InstPtr]=type+"0"+dataTable[it][2];
            }
            InstPtr++;
            break;
        }
    }       
}




//Perform the commands
int enact(string (&dataTable)[300][3],int &symCtr,int &dataCtr,int (&gotoPlace)[100][2],int &gotoCtr){
    if(com[0]==""){
        return 1;
    }
    dataTable[symCtr][0]=com[0];
    dataTable[symCtr][1]="L";
    dataTable[symCtr][2]=to_string(InstPtr);
    symCtr++;
    for(int i=0;i<com.size();i++){
        if(com[i]=="rem"){
            i=com.size();
        }else if(com[i]=="input"){
            SML[InstPtr]="10"+to_string(dataCtr);
            InstPtr++;
        }else if(com[i]=="print"){
            for(int it=0;it<300;it++){
                if(com[i+1]==dataTable[it][0]){
                    SML[InstPtr]="11"+dataTable[it][3];
                    InstPtr++;
                    i=300;
                }
            }
        }else if(com[i]=="end"){
            SML[InstPtr]="4300";
            InstPtr++;
        }else if(com[i]=="goto"){
            gotos(stoi(com[i+1]),40,stoi(com[0]),dataTable);
            i=300;
        }else if(com[i]=="if"){
            vector<char> command=spacer(com[i+1]);
            int caser;
            int loc;
            for (int it=0;it<command.size();it++){
                if(command[it]=='!'){
                    loc=it;
                    caser=1;
                    it=command.size();
                }else if(command[it]=='='){
                    loc=it;
                    caser=2;
                    it=command.size();
                }else if(command[it]=='<'){
                    loc=it;
                    if(command[it+2]=='='){
                        caser=5;
                    }else{
                        caser=3;
                    }
                    it=command.size();
                }else if(command[it]=='>'){
                    loc=it;
                    if(command[it+2]=='='){
                        caser=6;
                    }else{
                        caser=4;
                    }
                    it=command.size();
                }
            }
            switch(caser){
                case 1:
                    condi(SML,string(1,command[loc-2]),"20");
                    condi(SML,command[loc+4]),"31");
                    gotos(stoi(com[i+3]),42,dataTable);
                    condi(SML,dataTable);
                    break;
                case 2:
                    condi(SML,41,dataTable);
                    break;
                case 3:
                    condi(SML,command[loc+2]),dataTable);
                    break;
                case 4:
                    condi(SML,dataTable);
                    break;
                case 5:
                    condi(SML,dataTable);
                    gotos(stoi(com[i+3]),dataTable);
                    break;
                case 6:
                    condi(SML,dataTable);
                    break;
            }
            i=com.size();
        }else{
            if(isdigit(com[i][0])){
                dataTable[symCtr][0]=com[i];
                dataTable[symCtr][1]="N";
                dataTable[symCtr][2]=to_string(InstPtr);
                symCtr++;
            }else{
                dataTable[symCtr][0]=com[i];
                dataTable[symCtr][1]="V ";
                dataTable[symCtr][2]=to_string(InstPtr);
                symCtr++;
            }
        }   
    }
}





int main(){
    //This is all establishment variables
    int CurrentDataCtr=99;
    int currentInstPtr=0;
    int currentSymCtr=1;
    int gotoCtr=0;
    int gotoPlace[100][2]={0};
    array<string,100> SML;
    string baseCommand;
    string name;
    string ofile;
    string mfile;
    
    //This is getting the names of the files to open
    cout<<"Please enter the name of the file you would like compiled,name);
    cout<<"\nPlease enter the name of the file you would like the symbol table entered into,ofile);
    cout<<"\n Please enter the name of hte file you would like the machine code stored in,mfile);
    
    //Lets open up the files
    ifstream baseFile(name);
    ofstream outFile(ofile);
    ofstream SMLFile(mfile);
    
    //Establish that Data Table
    string dataTable[300][3];
    dataTable[0][0]="Symbol";
    dataTable[0][1]="Type";
    dataTable[0][2]="Location";
    
    //Initial Processing - Grabbing lines and operating on them
    while(getline(baseFile,baseCommand)){
        vector<string> command=parse(baseCommand);
        int condition=enact(dataTable,CurrentDataCtr,gotoCtr);
        if (CurrentDataCtr<=currentInstPtr){  //Checks to make sure data and commands dont ovelap
            cout<<"This code is too long,and is running into issues of overlapping in memory."<<endl;
            exit(EXIT_FAILURE);
        }
        if(condition==1){  //Handles end
            break;
        }
    }
    
    baseFile.close();
    
    //Print the data table to the outfile
    outFile<<dataTable[0][0]<<" "<<dataTable[0][1]<<" "<<dataTable[0][2]<<endl;
    for (int i=1;i<=currentSymCtr;i++){
        for(int it=0;it<3;it++){
            outFile<<dataTable[i][0]<<"      "<<dataTable[i][1]<<"      "<<dataTable[i][2]<<"      "<<endl;
        }
    }
    outFile.close();
    
    //Fix any gotos that need remaking
    for(int i=0; i<sizeof(gotoPlace);i++){
        for(int it=0; it<sizeof(dataTable);it++){
            if(dataTable[it][0]==""){
                break;
            }
            if(dataTable[it][0]==to_string(gotoPlace[i][0])){
                if(dataTable[it][2].size()<2){
                    SML[gotoPlace[i][1]]+="0"+dataTable[it][2];
                }else{
                    SML[gotoPlace[i][1]]+=dataTable[it][2];
                }
            }
        }
    }
    
    //Finally print the SML file
    for (int i=0;i<currentInstPtr;i++){
        SMLFile<<SML[i]<<endl;
    }
    SMLFile.close();
    
    return 0;
}

很抱歉,如果我的缩进不一致,我从dev中复制并粘贴到了代码段中,所以SO不喜欢它,因此我必须仔细检查并手动缩进每一行

最后包括的是我当前标题为test.txt的测试文件。这是将通过编译器运行的代码

10 rem why must this code hurt me so
20 input x
30 input y
40 if (x!=y) goto 60
50 goto 80
60 print x
70 print y
80 end

所以我不知道这是怎么回事。我们将非常感谢您提供的任何帮助。 谢谢大家

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)