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


C++ TokenStream::GoFirst方法代码示例

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


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

示例1: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	Initialize_ProductionTable();

	//initializing the predefine constants
	Initializing_SimbolTable();

	std::cout<<"Insert the mathematic expression:\n";

	//input will be my InputStream
	std::string input;
	std::getline( std::cin, input);
	
	//lets pass the lexer over the input
	Lexer* plex = new Lexer(input);
	TokenStream* ptokstrm = new TokenStream();
	try
		{
	ptokstrm = plex->Analize();
		}
	catch( UnExpextedSimbol e )
		{
		std::cout<<"\n\n"<< e.what();
		::getch();
		exit(0);
		}

	#pragma region Lexer Status, in Case of debugging
	#ifdef DEBUG
		std::cout<<"\nLEXER STATUS\n~~~~~~~~~~~~";
		std::cout<<"\n-----------------------------------------------------";
		std::cout<<"\n| The TokenStream\n|\n";
		
		Token tmp_token;
		ptokstrm->GoFirst();
		std::cout<<"| ";
		while( !ptokstrm->EndToken() )
			{
			std::cout<<ptokstrm->GetCurrent();
			ptokstrm->NextToken();
			}

		std::cout<<"\n|\n-----------------------------------------------------";
		std::cout<<"\n| The Token Atributes\n|\n";
		ptokstrm->GoFirst();

		std::cout<<"|    Tag\tPosition in Simbol Table\n";
		std::cout<<"|    ~~~\t~~~~~~~~~~~~~~~~~~~~~~~~\n";
		while( !ptokstrm->EndToken() )
			{	
			//I want the index position of GetCurrent().data but it does't let
			//me do iterator arithmetics, so I do this stinky thing
			if( ptokstrm->GetCurrent().data != SimbolTable.end() )
				{
			int tmp_cont=0;
			stdext::hash_map<std::string,double>::iterator tmp_it = SimbolTable.begin();
			while( tmp_it != ptokstrm->GetCurrent().data )
				{
				++tmp_cont;
				++tmp_it;
				}
			std::cout<<"|    "<<ptokstrm->GetCurrent()/*Hete it is the tagm but it is the same to show the token because of the operator <<*/<<
				"\t\t"<< tmp_cont<<'\n';
			ptokstrm->NextToken();
				}else{//If the position of the table is endm so I say NULL
			std::cout<<"|    "<<ptokstrm->GetCurrent()/*Hete it is the tagm but it is the same to show the token because of the operator <<*/<<
				"\t\t"<< "NULL"<<'\n';
			ptokstrm->NextToken();
				}
			}


		std::cout<<"|\n-----------------------------------------------------";
		std::cout<<"\n| The Simbol Table\n|\n";
		//std::copy(SimbolTable.begin(),SimbolTable.end(),std::ostream_iterator<std::pair<std::string,double>>(std::cout));
		std::cout<<"|      Lexeme\t      Value\n";
		std::cout<<"|      ~~~~~~\t      ~~~~~\n";
		stdext::hash_map<std::string,double>::iterator it = SimbolTable.begin();
		int index=0;
		while( it != SimbolTable.end() )
			{
			std::cout<<"| "<<index<<")     "<<*it;
			++index;
			++it;
			}
		std::cout<<"| "<<"NULL)\n";

		std::cout<<"|\n-----------------------------------------------------";
		//let's put it in the begining again
		ptokstrm->GoFirst();
	#endif
	#pragma endregion

	Parser* ppar = new Parser( *ptokstrm );
	Dash_Structures::DBTree<Token>* pSyntaxTree;
	try
		{
	pSyntaxTree = ppar->Analize();
		}
	catch( BadSintax e )
//.........这里部分代码省略.........
开发者ID:bobxiv,项目名称:SimpleCalc,代码行数:101,代码来源:Simple_C++_Calc.cpp


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