当前位置: 首页>>代码示例>>C++>>正文


C++ Symbol::GetCount方法代码示例

本文整理汇总了C++中Symbol::GetCount方法的典型用法代码示例。如果您正苦于以下问题:C++ Symbol::GetCount方法的具体用法?C++ Symbol::GetCount怎么用?C++ Symbol::GetCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symbol的用法示例。


在下文中一共展示了Symbol::GetCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fin

SymbolTable::SymbolTable(string file_name) {
	file = file_name;

	ifstream fin(file.c_str());
	ofstream fout("data/symbol_table.txt");
	Symbol symbol = Symbol(file);
	Table table[ symbol.GetCount() ];

	string line;
	int count = 0;
	int level_max = 0;
	/*------temp save for table------*/
	int level = 0;
	string symbol_name = "";
	string type_name = "";
	bool array_bool = false;
	bool function_bool = false;

	Origin();

	while(getline(fin, line)) {
		istringstream fin_word(line);
		string word = "";
		string remain = "";
		int pos = 0;

		while(fin_word >> word) {
			while(word != "") {
				if((pos = Check(word)) != -1) {
					if(pos != 0) {
						remain = word.substr(pos);
						word = word.substr(0, pos);
					}
					else {
						remain = word.substr(pos + length(word));
						word = word.substr(0, length(word));
					}
				}

				/*-----save in table------*/
				if( FindKeyWord(word) ) {
					type_name = word;
				}
				else {
					if(type_name != "") {
						if(word == ";" || word == "," || word == ")" || word == "=" || word == "(" || word == "[") {
							if(word == ";" || word == "," || word == ")" || word == "=") {
								array_bool = false;
								function_bool = false;
							}
							else if(word == "(") {
								level = 0;
								array_bool = false;
								function_bool = true;
							}
							else if(word == "[") {
								array_bool = true;
								function_bool = false;
							}

							table[count].Set(level, symbol_name, type_name, array_bool, function_bool);
							count = count + 1;
							type_name = "";
						}
						else {
							symbol_name = word;
						}
					}
				}

				if(word == "{" || word == "(") {
					level = level + 1;
				}
				else if(word == ")") {
					level = level - 1;
				}

				if(level > level_max) {
					level_max = level;
				}
				/*------------------------*/

				pos = 0;
				word = remain;
				remain = "";
			}
		}
	}

	int level_temp = 0;
	while(level_temp <= level_max) {
		for(int i = 0; i < (sizeof(table)/sizeof(*table)); i++) {
			if(table[i].GetLevel() == level_temp) {
				if(table[i].GetLevel() == table[i - 1].GetLevel() + 1) {
					scope = scope + 1;
				}
					table[i].SetScope(scope);
			}
		}

//.........这里部分代码省略.........
开发者ID:HsuTing,项目名称:compiler3,代码行数:101,代码来源:symbol.cpp


注:本文中的Symbol::GetCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。