アセンブリ命令を含む単純なテキストファイルを調べようとしていますが、次のようになります
TOP NOP
VAL INT 0
TAN LA 2,1
これはほんの一例ですので、どのように機能するかをお見せします。基本的に、最初のラベルを取得してラベルに配置し、次に NOP、INT、LA の 2 番目のラベルをオペコードに配置します。
その後、最初の引数 (0 と 2) を受け取り、それらを arg1 に配置します。ただし、ここで私の問題が発生します。現在のコードでは、引数を文字列に配置したときに得られる出力はそのままです
TOP
0
2
明らかに、最後の2つだけを取得したいのですが、最初の引数でTOPがそこに投げ込まれないようにするにはどうすればよいですか?
#include <string>
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <fstream>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
// If no extra file is provided then exit the program with error message
if (argc <= 1)
{
cout << "Correct Usage: " << argv[0] << " <Filename>" << endl;
exit (1);
}
// Array to hold the registers and initialize them all to zero
int registers [] = {0,0,0,0,0,0,0,0};
string memory [16000];
string Symtablelab[1000];
int Symtablepos[1000];
string line;
string label;
string opcode;
string arg1;
string arg2;
// Open the file that was input on the command line
ifstream myFile;
myFile.open(argv[1]);
if (!myFile.is_open())
{
cerr << "Cannot open the file." << endl;
}
int counter = 0;
int i = 0;
int j = 0;
while (getline(myFile, line, '\n'))
{
if (line[0] == '#')
{
continue;
}
if (line.length() == 0)
{
continue;
}
if (line[0] != '\t' && line[0] != ' ')
{
string delimeters = "\t ";
int current;
int next = -1;
current = next + 1;
next = line.find_first_of( delimeters, current);
label = line.substr( current, next - current );
Symtablelab[i] = label;
current = next + 1;
next = line.find_first_of(delimeters, current);
opcode = line.substr(current, next - current);
if (opcode != "WORDS" && opcode != "INT")
{
counter += 3;
}
if (opcode == "INT")
{
counter++;
}
delimeters = ", \n\t";
current = next + 1;
next = line.find_first_of(delimeters, current);
arg1 = line.substr(current, next-current);
cout << arg1<<endl;
i++;
}
}