Ejemplo n.º 1
0
bool
ZDriver::writeSource( void )
{
	std::ofstream out;
	bool isOk = false;

	getFileName( myFileName, ".cpp" );
	out.open( myFileName.c_str() );

	if ( out.is_open() )
	{
		myCurLineNum = 1;
		myPimplName = "priv";
		myPimplName.append( getParserName() );
		myPimplName.append( "Impl" );

		out << "// This file auto-generated from " << getParserName()
			<< ".lem by " << VersionInfo::appName() << " version "
			<< VersionInfo::appVersion() << endl();
		out << "// Editing of this file strongly discouraged." << endl();

		emitValue( getValue( "include" ), out );
		
		out << endl() << "#include <Core.h>" << endl();
		
		std::string incName;
		Util::getFileName( incName, std::string(), getSourceFile(), ".h" );
		out << endl() << "#include \"" << incName << "\"" << endl();

		out << endl() << "#include <utility>" << endl();
		out << "#include <stack>" << endl();
		out << "#include <map>" << endl();
		out << "#include <vector>" << endl();
		out << "#include <iostream>" << endl();
		out << "#include <Util/Any.h>" << endl();

		if ( ! myNameSpace.empty() )
		{
			emitFuncBreak( out );
			out << "using " << myNameSpace;
			if ( *(myNameSpace.end()-1) != ':' )
				out << "::";
			out << getParserName() << ";" << endl();
		}
		writeImplClassDecl( out );
		writeParserCtorDtor( out );
		writeMainParserFunc( out );
		writeImplClassCtorDtor( out );
		writeShiftFunc( out );
		writeReduceFunc( out );
		writeAcceptFunc( out );
		writeDestructorHandler( out );
		writeParserUtil( out );
		writeErrorRoutines( out );
		emitValue( getValue( "code" ), out );

		isOk = true;
	}

	return isOk;
}
Ejemplo n.º 2
0
void Upload::getParams(const UserConnection& aSource, StringMap& params) {
	Transfer::getParams(aSource, params);
	params["source"] = getSourceFile();
}
Ejemplo n.º 3
0
void
ZDriver::emitRule( const Rule *rp, std::ostream &out )
{
	std::string rpCode = rp->getCode();
	std::string::size_type curPos;
	int codeLine = rp->getCodeLine();

	while ( rpCode[0] == ' ' || rpCode[0] == '\t' || rpCode[0] == '\n' )
	{
		if ( rpCode[0] == '\n' )
			++codeLine;
		rpCode.erase( rpCode.begin() );
	}

	emitLineInfo( getSourceFile(), codeLine, out );

	const Rule::RHSList &rhs = rp->getRHS();
	Rule::RHSListConstIter ri, re;

	if ( ! rpCode.empty() )
	{
		curPos = 0;
		rpCode.insert( curPos, "            " );
		while ( curPos != std::string::npos )
		{
			curPos = rpCode.find( '\n', curPos );
			if ( curPos != std::string::npos )
			{
				incOutLine();
				++curPos;
				rpCode.insert( curPos, "        " );
			}
		}

		while ( rpCode[rpCode.size() - 1] == ' ' ||
				rpCode[rpCode.size() - 1] == '\t' )
			rpCode.erase( rpCode.end() - 1 );

		std::string replStr = "Util::any_cast< ";
		Symbol *lhsSym = SymbolTable::get()->find( rp->getLHS() );
		replStr.append( lhsSym->getDataType() );
		replStr.append( " >( data )" );
		substCode( rpCode, rp->getLHSAlias(), replStr, true,
				   lhsSym->getDataType() );

		const std::string &tokenType = getValue( "token_type" ).first;
		
		for ( ri = rhs.begin(), re = rhs.end(); ri != re; ++ri )
		{
			Symbol *sp = SymbolTable::get()->find( (*ri).first );
			const std::string &dataType = sp->getDataType();
			std::ostringstream tmpOut;
			
			replStr = "Util::any_cast< ";
			if ( Symbol::NONTERMINAL == sp->getType() && ! dataType.empty() )
				replStr.append( dataType );
			else
				replStr.append( tokenType );
			replStr.append( " >( rhsData[" );
			tmpOut << ( ri - rhs.begin() );
			replStr.append( tmpOut.str() );
			replStr.append( "] )" );

			substCode( rpCode, (*ri).second, replStr );
		}

		out << rpCode;
	}

	emitLineInfo( myFileName, getOutLine(), out );

	for ( ri = rhs.begin(), re = rhs.end(); ri != re; ++ri )
	{
		Symbol *sp = SymbolTable::get()->find( (*ri).first );
		if ( (*ri).second.empty() )
		{
			out << "            callDtor( " << sp->getIndex()
				<< ", rhsData[" << ( ri - rhs.begin() )
				<< "] );" << endl();
		}
	}
}