예제 #1
0
LL1Parser::LL1Parser(list<Token> tokens) :_tokens(tokens)
{
	_Done = false;
	Token push("$", TokenType::UNDEFINED);
	_tokens.push_back(push);
	_currentToken = _tokens.begin();
	buildRuleTable();
}
예제 #2
0
파일: ZDriver.cpp 프로젝트: iangodin/lime
void
ZDriver::writeParserUtil( std::ostream &out )
{
	emitFuncBreak( out );
	out << "void " << myPimplName << "::popStack( void )" << endl();
	out << "{" << endl();
	out << "    callDtor( myStack.top().first.second, myStack.top().second );"
		<< endl();
	out << "    myStack.pop();" << endl();
	out << "}" << endl();

	emitFuncBreak( out );
	out << "ParserAct " << myPimplName
		<< "::findParserAction( int &newVal, int tok )" << endl();
	out << "{" << endl();
	out << "    int stateNum;" << endl();
	out << "    ParserAct retval = PA_NOP;" << endl();
	out << "    bool found = false;" << endl();
	out << endl();
	out << "    stateNum = myStack.empty() ? 0 : myStack.top().first.first;"
		<< endl();
	out << "    ActionMap::iterator i = myStates[stateNum].find( tok );"
		<< endl();
	out << "    if ( tok >= 0 && tok <= "
		<< SymbolTable::get()->getNumSymbols() << " )" << endl();
	out << "    {" << endl();
	out << "        if ( i != myStates[stateNum].end() )" << endl();
	out << "        {" << endl();
	out << "            retval = (*i).second.first;" << endl();
	out << "            newVal = (*i).second.second;" << endl();
	out << "            found = true;" << endl();
	out << "        }" << endl();
	out << "    }" << endl();
	out << "    else if ( ! myStates[stateNum].empty() )" << endl();
	out << "    {" << endl();
	out << "        retval = PA_NOP;" << endl();
	out << "        newVal = 0;" << endl();
	out << "        found = true;" << endl();
	out << "    }" << endl();
	out << endl();
	out << "    if ( ! found )" << endl();
	out << "    {" << endl();
	out << "        retval = myStateDefaultActions[stateNum].first;" << endl();
	out << "        newVal = myStateDefaultActions[stateNum].second;" << endl();
	out << "    }" << endl();

	out << "    return retval;" << endl();
	out << "}" << endl();

	emitFuncBreak( out );

	writeStateTable( out );
	writeRuleTable( out );

	emitFuncBreak( out );

	out << "void " << myPimplName << "::initTables( void )" << endl();
	out << "{" << endl();
	buildStateTable( out );
	buildRuleTable( out );
	out << "}" << endl();
}