本文整理汇总了C++中SymbolTable::GetAdress方法的典型用法代码示例。如果您正苦于以下问题:C++ SymbolTable::GetAdress方法的具体用法?C++ SymbolTable::GetAdress怎么用?C++ SymbolTable::GetAdress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable
的用法示例。
在下文中一共展示了SymbolTable::GetAdress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char* argv[]){
string filename = argv[1];
size_t extension = filename.find(".asm");
if (extension != string::npos){
Parser p(filename);
filename.erase(filename.find(".asm")); // remove the extension so we can create the new file with .hack instead
// Generate Symbol table
SymbolTable sTable = SymbolTable();
int cAdress = 0;
while (p.hasMoreCommands()){
if (p.commandType() == L_COMMAND){
sTable.addEntry(p.symbol(), cAdress);
} else if (p.commandType() == A_COMMAND || p.commandType() == C_COMMAND) {
++cAdress;
}
p.advance();
}
// Generate code
filename += ".hack";
ofstream outfile(filename);
int nextRAMAdress = 16;
p.reset();
while (p.hasMoreCommands()){
if (p.commandType() == C_COMMAND){
string c("111");
c += comp(p.comp());
c += dest(p.dest());
c += jump(p.jump());
outfile << c << endl;
} else if (p.commandType() == A_COMMAND){
string symbol = p.symbol();
if (symbol.substr(0, 1).find_first_of("0123456789") != string::npos){ // If symbol starts with a digit.. it is a number
outfile << decimalToBinary(atoi(p.symbol().c_str())) << endl;
} else {
// else we need to find it in the symbol table
if (!sTable.contains(symbol)){
sTable.addEntry(symbol, nextRAMAdress);
++nextRAMAdress;
}
outfile << decimalToBinary(sTable.GetAdress(symbol)) << endl;
}
}
p.advance(); // if this is at the beginning of the loop the program will skip the first instruction
}
outfile.close();
} else {
cout << "Could not assemble program, incorrect file format/extension!" << endl;
cout << "Exiting.. ";
}
return 0;
}