Example #1
0
void CSharpFlatCodeGen::COND_TRANSLATE()
{
	out << 
		"	_widec = " << GET_KEY() << ";\n";

	out <<
		"   _keys = " << vCS() << "<<1;\n"
		"   _conds = " << CO() << "[" << vCS() << "];\n"
//		"	_keys = " << ARR_OFF( CK(), "(" + vCS() + "<<1)" ) << ";\n"
//		"	_conds = " << ARR_OFF( C(), CO() + "[" + vCS() + "]" ) << ";\n"
		"\n"
		"	_slen = " << CSP() << "[" << vCS() << "];\n"
		"	if (_slen > 0 && " << CK() << "[_keys] <=" 
			<< GET_WIDE_KEY() << " &&\n"
		"		" << GET_WIDE_KEY() << " <= " << CK() << "[_keys+1])\n"
		"		_cond = " << C() << "[_conds+" << GET_WIDE_KEY() << " - " << 
			CK() << "[_keys]];\n"
		"	else\n"
		"		_cond = 0;"
		"\n";
	/*  XXX This version of the code doesn't work because Mono is weird.  Works
	 *  fine in Microsoft's csc, even though the bug report filed claimed it
	 *  didn't.
		"	_slen = " << CSP() << "[" << vCS() << "];\n"
		"	_cond = _slen > 0 && " << CK() << "[_keys] <=" 
			<< GET_WIDE_KEY() << " &&\n"
		"		" << GET_WIDE_KEY() << " <= " << CK() << "[_keys+1] ?\n"
		"		" << C() << "[_conds+" << GET_WIDE_KEY() << " - " << CK() 
			<< "[_keys]] : 0;\n"
		"\n";
		*/
	out <<
		"	switch ( _cond ) {\n";
	for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
		GenCondSpace *condSpace = csi;
		out << "	case " << condSpace->condSpaceId + 1 << ": {\n";
		out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
				KEY(condSpace->baseKey) << " + (" << GET_KEY() << 
				" - " << KEY(keyOps->minKey) << "));\n";

		for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
			out << TABS(2) << "if ( ";
			CONDITION( out, *csi );
			Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
			out << " ) _widec += " << condValOffset << ";\n";
		}

		out << "		}\n";
		out << "		break;\n";
	}

	SWITCH_DEFAULT();

	out <<
		"	}\n";
}
Example #2
0
void CSharpTabCodeGen::LOCATE_TRANS()
{
    out <<
        "	_keys = " << KO() + "[" + vCS() + "]" << ";\n"
        "	_trans = " << CAST(transType) << IO() << "[" << vCS() << "];\n"
        "\n"
        "	_klen = " << SL() << "[" << vCS() << "];\n"
        "	if ( _klen > 0 ) {\n"
        "		" << signedKeysType << " _lower = _keys;\n"
        "		" << signedKeysType << " _mid;\n"
        "		" << signedKeysType << " _upper = " << CAST(signedKeysType) <<
        " (_keys + _klen - 1);\n"
        "		while (true) {\n"
        "			if ( _upper < _lower )\n"
        "				break;\n"
        "\n"
        "			_mid = " << CAST(signedKeysType) <<
        " (_lower + ((_upper-_lower) >> 1));\n"
        "			if ( " << GET_WIDE_KEY() << " < " << K() << "[_mid] )\n"
        "				_upper = " << CAST(signedKeysType) << " (_mid - 1);\n"
        "			else if ( " << GET_WIDE_KEY() << " > " << K() << "[_mid] )\n"
        "				_lower = " << CAST(signedKeysType) << " (_mid + 1);\n"
        "			else {\n"
        "				_trans += " << CAST(transType) << " (_mid - _keys);\n"
        "				goto _match;\n"
        "			}\n"
        "		}\n"
        "		_keys += " << CAST(keysType) << " _klen;\n"
        "		_trans += " << CAST(transType) << " _klen;\n"
        "	}\n"
        "\n"
        "	_klen = " << RL() << "[" << vCS() << "];\n"
        "	if ( _klen > 0 ) {\n"
        "		" << signedKeysType << " _lower = _keys;\n"
        "		" << signedKeysType << " _mid;\n"
        "		" << signedKeysType << " _upper = " << CAST(signedKeysType) <<
        " (_keys + (_klen<<1) - 2);\n"
        "		while (true) {\n"
        "			if ( _upper < _lower )\n"
        "				break;\n"
        "\n"
        "			_mid = " << CAST(signedKeysType) <<
        " (_lower + (((_upper-_lower) >> 1) & ~1));\n"
        "			if ( " << GET_WIDE_KEY() << " < " << K() << "[_mid] )\n"
        "				_upper = " << CAST(signedKeysType) << " (_mid - 2);\n"
        "			else if ( " << GET_WIDE_KEY() << " > " << K() << "[_mid+1] )\n"
        "				_lower = " << CAST(signedKeysType) << " (_mid + 2);\n"
        "			else {\n"
        "				_trans += " << CAST(transType) << "((_mid - _keys)>>1);\n"
        "				goto _match;\n"
        "			}\n"
        "		}\n"
        "		_trans += " << CAST(transType) << " _klen;\n"
        "	}\n"
        "\n";
}
Example #3
0
void CSharpTabCodeGen::COND_TRANSLATE()
{
    out <<
        "	_widec = " << GET_KEY() << ";\n"
        "	_klen = " << CL() << "[" << vCS() << "];\n"
        "	_keys = " << CAST(keysType) << " ("<< CO() << "[" << vCS() << "]*2);\n"
        "	if ( _klen > 0 ) {\n"
        "		" << signedKeysType << " _lower = _keys;\n"
        "		" << signedKeysType << " _mid;\n"
        "		" << signedKeysType << " _upper = " << CAST(signedKeysType) <<
        " (_keys + (_klen<<1) - 2);\n"
        "		while (true) {\n"
        "			if ( _upper < _lower )\n"
        "				break;\n"
        "\n"
        "			_mid = " << CAST(signedKeysType) <<
        " (_lower + (((_upper-_lower) >> 1) & ~1));\n"
        "			if ( " << GET_WIDE_KEY() << " < " << CK() << "[_mid] )\n"
        "				_upper = " << CAST(signedKeysType) << " (_mid - 2);\n"
        "			else if ( " << GET_WIDE_KEY() << " > " << CK() << "[_mid+1] )\n"
        "				_lower = " << CAST(signedKeysType) << " (_mid + 2);\n"
        "			else {\n"
        "				switch ( " << C() << "[" << CO() << "[" << vCS() << "]"
        " + ((_mid - _keys)>>1)] ) {\n";

    for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
        GenCondSpace *condSpace = csi;
        out << "	case " << condSpace->condSpaceId << ": {\n";
        out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
            KEY(condSpace->baseKey) << " + (" << GET_KEY() <<
            " - " << KEY(keyOps->minKey) << "));\n";

        for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
            out << TABS(2) << "if ( ";
            CONDITION( out, *csi );
            Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
            out << " ) _widec += " << condValOffset << ";\n";
        }

        out <<
            "		break;\n"
            "	}\n";
    }

    SWITCH_DEFAULT();

    out <<
        "				}\n"
        "				break;\n"
        "			}\n"
        "		}\n"
        "	}\n"
        "\n";
}
Example #4
0
void FlatCodeGen::LOCATE_TRANS()
{
	out <<
		"	_keys = " << ARR_OFF( K(), "(" + vCS() + "<<1)" ) << ";\n"
		"	_inds = " << ARR_OFF( I(), IO() + "[" + vCS() + "]" ) << ";\n"
		"\n"
		"	_slen = " << SP() << "[" << vCS() << "];\n"
		"	_trans = _inds[ _slen > 0 && _keys[0] <=" << GET_WIDE_KEY() << " &&\n"
		"		" << GET_WIDE_KEY() << " <= _keys[1] ?\n"
		"		" << GET_WIDE_KEY() << " - _keys[0] : _slen ];\n"
		"\n";
}
Example #5
0
void TabCodeGen::LOCATE_TRANS()
{
	out <<
		"	_keys = " << ARR_OFF( K(), KO() + "[" + vCS() + "]" ) << ";\n"
		"	_trans = " << IO() << "[" << vCS() << "];\n"
		"\n"
		"	_klen = " << SL() << "[" << vCS() << "];\n"
		"	if ( _klen > 0 ) {\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_lower = _keys;\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_mid;\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_upper = _keys + _klen - 1;\n"
		"		while (1) {\n"
		"			if ( _upper < _lower )\n"
		"				break;\n"
		"\n"
		"			_mid = _lower + ((_upper-_lower) >> 1);\n"
		"			if ( " << GET_WIDE_KEY() << " < *_mid )\n"
		"				_upper = _mid - 1;\n"
		"			else if ( " << GET_WIDE_KEY() << " > *_mid )\n"
		"				_lower = _mid + 1;\n"
		"			else {\n"
		"				_trans += " << CAST(UINT()) << "(_mid - _keys);\n"
		"				goto _match;\n"
		"			}\n"
		"		}\n"
		"		_keys += _klen;\n"
		"		_trans += _klen;\n"
		"	}\n"
		"\n"
		"	_klen = " << RL() << "[" << vCS() << "];\n"
		"	if ( _klen > 0 ) {\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_lower = _keys;\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_mid;\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
		"		while (1) {\n"
		"			if ( _upper < _lower )\n"
		"				break;\n"
		"\n"
		"			_mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
		"			if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
		"				_upper = _mid - 2;\n"
		"			else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
		"				_lower = _mid + 2;\n"
		"			else {\n"
		"				_trans += " << CAST(UINT()) << "((_mid - _keys)>>1);\n"
		"				goto _match;\n"
		"			}\n"
		"		}\n"
		"		_trans += _klen;\n"
		"	}\n"
		"\n";
}
Example #6
0
void TabCodeGen::COND_TRANSLATE()
{
	out << 
		"	_widec = " << GET_KEY() << ";\n"
		"	_klen = " << CL() << "[" << vCS() << "];\n"
		"	_keys = " << ARR_OFF( CK(), "(" + CO() + "[" + vCS() + "]*2)" ) << ";\n"
		"	if ( _klen > 0 ) {\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_lower = _keys;\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_mid;\n"
		"		" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
		"		while (1) {\n"
		"			if ( _upper < _lower )\n"
		"				break;\n"
		"\n"
		"			_mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
		"			if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
		"				_upper = _mid - 2;\n"
		"			else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
		"				_lower = _mid + 2;\n"
		"			else {\n"
		"				switch ( " << C() << "[" << CO() << "[" << vCS() << "]"
							" + ((_mid - _keys)>>1)] ) {\n";

	for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
		GenCondSpace *condSpace = csi;
		out << "	case " << condSpace->condSpaceId << ": {\n";
		out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
				KEY(condSpace->baseKey) << " + (" << GET_KEY() << 
				" - " << KEY(keyOps->minKey) << "));\n";

		for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
			out << TABS(2) << "if ( ";
			CONDITION( out, *csi );
			Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
			out << " ) _widec += " << condValOffset << ";\n";
		}

		out << 
			"		break;\n"
			"	}\n";
	}

	SWITCH_DEFAULT();

	out << 
		"				}\n"
		"				break;\n"
		"			}\n"
		"		}\n"
		"	}\n"
		"\n";
}
Example #7
0
void CSharpFlatCodeGen::LOCATE_TRANS()
{
	out <<
		"	_keys = " << vCS() << "<<1;\n"
		"	_inds = " << IO() << "[" << vCS() << "];\n"
		"\n"
		"	_slen = " << SP() << "[" << vCS() << "];\n"
		"	_trans = " << I() << "[_inds + (\n"
		"		_slen > 0 && " << K() << "[_keys] <=" << GET_WIDE_KEY() << " &&\n"
		"		" << GET_WIDE_KEY() << " <= " << K() <<"[_keys+1] ?\n"
		"		" << GET_WIDE_KEY() << " - " << K() << "[_keys] : _slen ) ];\n"
		"\n";
}
Example #8
0
void TabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish )
{
	if ( prePushExpr != 0 ) {
		ret << "{";
		INLINE_LIST( ret, prePushExpr, 0, false, false );
	}

	ret << "{" << STACK() << "[" << TOP() << "++] = " << vCS() << "; " << vCS() << " = " << 
			callDest << "; " << CTRL_FLOW() << "goto _again;}";

	if ( prePushExpr != 0 )
		ret << "}";
}
Example #9
0
void OCamlTabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish )
{
	if ( prePushExpr != 0 ) {
		ret << "begin ";
		INLINE_LIST( ret, prePushExpr, 0, false );
	}

	ret << "begin " << AT( STACK(), POST_INCR(TOP()) ) << " <- " << vCS() << "; ";
  ret << vCS() << " <- " << callDest << "; " << CTRL_FLOW() << "raise Goto_again end ";

	if ( prePushExpr != 0 )
		ret << "end";
}
Example #10
0
void TabCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish )
{
	if ( prePushExpr != 0 ) {
		ret << "{";
		INLINE_LIST( ret, prePushExpr, 0, false, false );
	}

	ret << "{" << STACK() << "[" << TOP() << "++] = " << vCS() << "; " << vCS() << " = (";
	INLINE_LIST( ret, ilItem->children, targState, inFinish, false );
	ret << "); " << CTRL_FLOW() << "goto _again;}";

	if ( prePushExpr != 0 )
		ret << "}";
}
Example #11
0
void OCamlTabCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish )
{
	if ( prePushExpr != 0 ) {
		ret << "begin ";
		INLINE_LIST( ret, prePushExpr, 0, false );
	}

	ret << "begin " << AT(STACK(), POST_INCR(TOP()) ) << " <- " << vCS() << "; " << vCS() << " <- (";
	INLINE_LIST( ret, ilItem->children, targState, inFinish );
	ret << "); " << CTRL_FLOW() << "raise Goto_again end ";

	if ( prePushExpr != 0 )
		ret << "end";
}
Example #12
0
void OCamlTabCodeGen::LOCATE_TRANS()
{
	out <<
		"	state.keys <- " << AT( KO(), vCS() ) << ";\n"
		"	state.trans <- " << CAST(transType) << AT( IO(), vCS() ) << ";\n"
		"\n"
		"	let klen = " << AT( SL(), vCS() ) << " in\n"
		"	if klen > 0 then begin\n"
		"		let lower : " << signedKeysType << " ref = ref state.keys in\n"
		"		let upper : " << signedKeysType << " ref = ref " << CAST(signedKeysType) << 
			"(state.keys + klen - 1) in\n"
		"		while !upper >= !lower do\n"
		"			let mid = " << CAST(signedKeysType) << " (!lower + ((!upper - !lower) / 2)) in\n"
		"			if " << GET_WIDE_KEY() << " < " << AT( K(), "mid" ) << " then\n"
		"				upper := " << CAST(signedKeysType) << " (mid - 1)\n"
		"			else if " << GET_WIDE_KEY() << " > " << AT( K(), "mid" ) << " then\n"
		"				lower := " << CAST(signedKeysType) << " (mid + 1)\n"
		"			else begin\n"
		"				state.trans <- state.trans + " << CAST(transType) << " (mid - state.keys);\n"
		"				raise Goto_match;\n"
		"			end\n"
		"		done;\n"
		"		state.keys <- state.keys + " << CAST(keysType) << " klen;\n"
		"		state.trans <- state.trans + " << CAST(transType) << " klen;\n"
		"	end;\n"
		"\n"
		"	let klen = " << AT( RL(), vCS() ) << " in\n"
		"	if klen > 0 then begin\n"
		"		let lower : " << signedKeysType << " ref = ref state.keys in\n"
		"		let upper : " << signedKeysType << " ref = ref " << CAST(signedKeysType) <<
			"(state.keys + (klen * 2) - 2) in\n"
		"		while !upper >= !lower do\n"
		"			let mid = " << CAST(signedKeysType) << " (!lower + (((!upper - !lower) / 2) land (lnot 1))) in\n"
		"			if " << GET_WIDE_KEY() << " < " << AT( K() , "mid" ) << " then\n"
		"				upper := " << CAST(signedKeysType) << " (mid - 2)\n"
		"			else if " << GET_WIDE_KEY() << " > " << AT( K(), "mid+1" ) << " then\n"
		"				lower := " << CAST(signedKeysType) << " (mid + 2)\n"
		"			else begin\n"
		"				state.trans <- state.trans + " << CAST(transType) << "((mid - state.keys) / 2);\n"
		"				raise Goto_match;\n"
		"		  end\n"
		"		done;\n"
		"		state.trans <- state.trans + " << CAST(transType) << " klen;\n"
		"	end;\n"
		"\n";
}
Example #13
0
void OCamlTabCodeGen::RET( ostream &ret, bool inFinish )
{
	ret << "begin " << vCS() << " <- " << AT(STACK(), PRE_DECR(TOP()) ) << "; ";

	if ( postPopExpr != 0 ) {
		ret << "begin ";
		INLINE_LIST( ret, postPopExpr, 0, false );
		ret << "end ";
	}

	ret << CTRL_FLOW() <<  "raise Goto_again end";
}
Example #14
0
void CSharpFlatCodeGen::RET( ostream &ret, bool inFinish )
{
	ret << "{" << vCS() << " = " << STACK() << "[--" << TOP() << "];";

	if ( postPopExpr != 0 ) {
		ret << "{";
		INLINE_LIST( ret, postPopExpr, 0, false );
		ret << "}";
	}

	ret << CTRL_FLOW() << "goto _again;}";
}
Example #15
0
void FlatCodeGen::COND_TRANSLATE()
{
	out << 
		"	_widec = " << GET_KEY() << ";\n";

	out <<
		"	_keys = " << ARR_OFF( CK(), "(" + vCS() + "<<1)" ) << ";\n"
		"	_conds = " << ARR_OFF( C(), CO() + "[" + vCS() + "]" ) << ";\n"
		"\n"
		"	_slen = " << CSP() << "[" << vCS() << "];\n"
		"	_cond = _slen > 0 && _keys[0] <=" << GET_WIDE_KEY() << " &&\n"
		"		" << GET_WIDE_KEY() << " <= _keys[1] ?\n"
		"		_conds[" << GET_WIDE_KEY() << " - _keys[0]] : 0;\n"
		"\n";

	out <<
		"	switch ( _cond ) {\n";
	for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
		GenCondSpace *condSpace = csi;
		out << "	case " << condSpace->condSpaceId + 1 << ": {\n";
		out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
				KEY(condSpace->baseKey) << " + (" << GET_KEY() << 
				" - " << KEY(keyOps->minKey) << "));\n";

		for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
			out << TABS(2) << "if ( ";
			CONDITION( out, *csi );
			Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
			out << " ) _widec += " << condValOffset << ";\n";
		}

		out << "		}\n";
		out << "		break;\n";
	}

	SWITCH_DEFAULT();

	out <<
		"	}\n";
}
Example #16
0
std::wostream &CSharpGotoCodeGen::TRANSITIONS()
{
	/* Emit any transitions that have functions and that go to 
	 * this state. */
	for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ ) {
		/* Write the label for the transition so it can be jumped to. */
		out << L"	tr" << trans->id << L": ";

		/* Destination state. */
		if ( trans->action != 0 && trans->action->anyCurStateRef() )
			out << L"_ps = " << vCS() << L";";
		out << vCS() << L" = " << trans->targ->id << L"; ";

		if ( trans->action != 0 ) {
			/* Write out the transition func. */
			out << L"goto f" << trans->action->actListId << L";\n";
		}
		else {
			/* No code to execute, just loop around. */
			out << L"goto _again;\n";
		}
	}
	return out;
}
Example #17
0
void FGotoCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;

	out << L"	{\n";

	if ( redFsm->anyRegCurStateRef() )
		out << L"	int _ps = 0;\n";

	if ( redFsm->anyConditions() )
		out << L"	" << WIDE_ALPH_TYPE() << L" _widec;\n";

	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			L"	if ( " << P() << L" == " << PE() << L" )\n"
			L"		goto _test_eof;\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n"
			L"		goto _out;\n";
	}

	out << L"_resume:\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			L"	switch ( " << FSA() << L"[" << vCS() << L"] ) {\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

	out << 
		L"	switch ( " << vCS() << L" ) {\n";
		STATE_GOTOS();
		SWITCH_DEFAULT() <<
		L"	}\n"
		L"\n";
		TRANSITIONS() << 
		L"\n";

	if ( redFsm->anyRegActions() )
		EXEC_ACTIONS() << L"\n";

	out << L"_again:\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			L"	switch ( " << TSA() << L"[" << vCS() << L"] ) {\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n"
			L"		goto _out;\n";
	}

	if ( !noEnd ) {
		out << 
			L"	if ( ++" << P() << L" != " << PE() << L" )\n"
			L"		goto _resume;\n";
	}
	else {
		out << 
			L"	" << P() << L" += 1;\n"
			L"	goto _resume;\n";
	}

	if ( testEofUsed )
		out << L"	_test_eof: {}\n";

	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out <<
			L"	if ( " << P() << L" == " << vEOF() << L" )\n"
			L"	{\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				L"	switch ( " << vCS() << L" ) {\n";

			for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
				if ( st->eofTrans != 0 )
					out << L"	case " << st->id << L": goto tr" << st->eofTrans->id << L";\n";
			}

			SWITCH_DEFAULT() <<
				L"	}\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				L"	switch ( " << EA() << L"[" << vCS() << L"] ) {\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				L"	}\n";
		}

		out <<
			L"	}\n"
			L"\n";
	}

	if ( outLabelUsed )
		out << L"	_out: {}\n";

	out << L"	}\n";
}
Example #18
0
void TabCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;

	out <<
		"	{\n"
		"	int _klen";

	if ( redFsm->anyRegCurStateRef() )
		out << ", _ps";

	out << 
		";\n"
		"	" << UINT() << " _trans;\n";

	if ( redFsm->anyConditions() )
		out << "	" << WIDE_ALPH_TYPE() << " _widec;\n";

	if ( redFsm->anyToStateActions() || redFsm->anyRegActions() 
			|| redFsm->anyFromStateActions() )
	{
		out << 
			"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << PTR_CONST_END() << 
					POINTER() << "_acts;\n"
			"	" << UINT() << " _nacts;\n";
	}

	out <<
		"	" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_keys;\n"
		"\n";

	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			"	if ( " << P() << " == " << PE() << " )\n"
			"		goto _test_eof;\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	if ( " << vCS() << " == " << redFsm->errState->id << " )\n"
			"		goto _out;\n";
	}

	out << "_resume:\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			"	_acts = " << ARR_OFF( A(),  FSA() + "[" + vCS() + "]" ) << ";\n"
			"	_nacts = " << CAST(UINT()) << " *_acts++;\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( *_acts++ ) {\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->anyConditions() )
		COND_TRANSLATE();

	LOCATE_TRANS();

	out << "_match:\n";

	if ( useIndicies )
		out << "	_trans = " << I() << "[_trans];\n";
	
	if ( redFsm->anyEofTrans() )
		out << "_eof_trans:\n";

	if ( redFsm->anyRegCurStateRef() )
		out << "	_ps = " << vCS() << ";\n";

	out <<
		"	" << vCS() << " = " << TT() << "[_trans];\n"
		"\n";

	if ( redFsm->anyRegActions() ) {
		out <<
			"	if ( " << TA() << "[_trans] == 0 )\n"
			"		goto _again;\n"
			"\n"
			"	_acts = " << ARR_OFF( A(), TA() + "[_trans]" ) << ";\n"
			"	_nacts = " << CAST(UINT()) << " *_acts++;\n"
			"	while ( _nacts-- > 0 )\n	{\n"
			"		switch ( *_acts++ )\n		{\n";
			ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
			redFsm->anyActionCalls() || redFsm->anyActionRets() )
		out << "_again:\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			"	_acts = " << ARR_OFF( A(), TSA() + "[" + vCS() + "]" ) << ";\n"
			"	_nacts = " << CAST(UINT()) << " *_acts++;\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( *_acts++ ) {\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	if ( " << vCS() << " == " << redFsm->errState->id << " )\n"
			"		goto _out;\n";
	}

	if ( !noEnd ) {
		out << 
			"	if ( ++" << P() << " != " << PE() << " )\n"
			"		goto _resume;\n";
	}
	else {
		out << 
			"	" << P() << " += 1;\n"
			"	goto _resume;\n";
	}
	
	if ( testEofUsed )
		out << "	_test_eof: {}\n";
	
	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out << 
			"	if ( " << P() << " == " << vEOF() << " )\n"
			"	{\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				"	if ( " << ET() << "[" << vCS() << "] > 0 ) {\n"
				"		_trans = " << ET() << "[" << vCS() << "] - 1;\n"
				"		goto _eof_trans;\n"
				"	}\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << PTR_CONST_END() << 
						POINTER() << "__acts = " << 
						ARR_OFF( A(), EA() + "[" + vCS() + "]" ) << ";\n"
				"	" << UINT() << " __nacts = " << CAST(UINT()) << " *__acts++;\n"
				"	while ( __nacts-- > 0 ) {\n"
				"		switch ( *__acts++ ) {\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				"		}\n"
				"	}\n";
		}
		
		out << 
			"	}\n"
			"\n";
	}

	if ( outLabelUsed )
		out << "	_out: {}\n";

	out << "	}\n";
}
Example #19
0
void CSharpTabCodeGen::NEXT( wostream &ret, int nextDest, bool inFinish )
{
	ret << vCS() << L" = " << nextDest << L";";
}
Example #20
0
void CSharpTabCodeGen::NEXT_EXPR( wostream &ret, GenInlineItem *ilItem, bool inFinish )
{
	ret << vCS() << L" = (";
	INLINE_LIST( ret, ilItem->children, 0, inFinish );
	ret << L");";
}
Example #21
0
void TabCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish )
{
	ret << vCS() << " = (";
	INLINE_LIST( ret, ilItem->children, 0, inFinish, false );
	ret << ");";
}
Example #22
0
void TabCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish )
{
	ret << vCS() << " = " << nextDest << ";";
}
Example #23
0
void TabCodeGen::TARGS( ostream &ret, bool inFinish, int targState )
{
	ret << "(" << vCS() << ")";
}
Example #24
0
void TabCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish )
{
	ret << "{" << vCS() << " = (";
	INLINE_LIST( ret, ilItem->children, 0, inFinish, false );
	ret << "); " << CTRL_FLOW() << "goto _again;}";
}
Example #25
0
void TabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish )
{
	ret << "{" << vCS() << " = " << gotoDest << "; " << 
			CTRL_FLOW() << "goto _again;}";
}
Example #26
0
void CSharpTabCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;
	initVarTypes();

	out <<
		L"	{\n"
		L"	" << klenType << L" _klen";

	if ( redFsm->anyRegCurStateRef() )
		out << L", _ps";

	out << 
		L";\n"
		L"	" << transType << L" _trans;\n";

	if ( redFsm->anyConditions() )
		out << L"	" << WIDE_ALPH_TYPE() << L" _widec;\n";

	if ( redFsm->anyToStateActions() || redFsm->anyRegActions() 
			|| redFsm->anyFromStateActions() )
	{
		out << 
			L"	int _acts;\n"
			L"	int _nacts;\n";
	}

	out <<
		L"	" << keysType << L" _keys;\n"
		L"\n";
//		L"	" << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << L"_keys;\n"

	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			L"	if ( " << P() << L" == " << PE() << L" )\n"
			L"		goto _test_eof;\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n"
			L"		goto _out;\n";
	}

	out << L"_resume:\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			L"	_acts = " << FSA() << L"[" + vCS() + L"]" << L";\n"
			L"	_nacts = " << A() << L"[_acts++];\n"
			L"	while ( _nacts-- > 0 ) {\n"
			L"		switch ( " << A() << L"[_acts++] ) {\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"		}\n"
			L"	}\n"
			L"\n";
	}

	if ( redFsm->anyConditions() )
		COND_TRANSLATE();

	LOCATE_TRANS();

	out << L"_match:\n";

	if ( useIndicies )
		out << L"	_trans = " << CAST(transType) << I() << L"[_trans];\n";
	
	if ( redFsm->anyEofTrans() )
		out << L"_eof_trans:\n";

	if ( redFsm->anyRegCurStateRef() )
		out << L"	_ps = " << vCS() << L";\n";

	out <<
		L"	" << vCS() << L" = " << TT() << L"[_trans];\n"
		L"\n";

	if ( redFsm->anyRegActions() ) {
		out <<
			L"	if ( " << TA() << L"[_trans] == 0 )\n"
			L"		goto _again;\n"
			L"\n"
			L"	_acts = " << TA() << L"[_trans]" << L";\n"
			L"	_nacts = " << A() << L"[_acts++];\n"
			L"	while ( _nacts-- > 0 )\n	{\n"
			L"		switch ( " << A() << L"[_acts++] )\n		{\n";
			ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"		}\n"
			L"	}\n"
			L"\n";
	}

	if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
			redFsm->anyActionCalls() || redFsm->anyActionRets() )
		out << L"_again:\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			L"	_acts = " << TSA() << L"[" << vCS() << L"]" << L";\n"
			L"	_nacts = " << A() << L"[_acts++];\n"
			L"	while ( _nacts-- > 0 ) {\n"
			L"		switch ( " << A() << L"[_acts++] ) {\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"		}\n"
			L"	}\n"
			L"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n"
			L"		goto _out;\n";
	}

	if ( !noEnd ) {
		out << 
			L"	if ( ++" << P() << L" != " << PE() << L" )\n"
			L"		goto _resume;\n";
	}
	else {
		out << 
			L"	" << P() << L" += 1;\n"
			L"	goto _resume;\n";
	}
	
	if ( testEofUsed )
		out << L"	_test_eof: {}\n";
	
	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out << 
			L"	if ( " << P() << L" == " << vEOF() << L" )\n"
			L"	{\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				L"	if ( " << ET() << L"[" << vCS() << L"] > 0 ) {\n"
				L"		_trans = " << CAST(transType) << L" (" << ET() <<
					L"[" << vCS() << L"] - 1);\n"
				L"		goto _eof_trans;\n"
				L"	}\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				L"	int __acts = " << 
						EA() << L"[" << vCS() << L"]" << L";\n"
				L"	int __nacts = " << 
				A() << L"[__acts++];\n"
				L"	while ( __nacts-- > 0 ) {\n"
				L"		switch ( " << A() << L"[__acts++] ) {\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				L"		}\n"
				L"	}\n";
		}
		
		out << 
			L"	}\n"
			L"\n";
	}

	if ( outLabelUsed )
		out << L"	_out: {}\n";

	out << L"	}\n";
}
Example #27
0
void FFlatCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;

	out << 
		L"	{\n"
		L"	int _slen";

	if ( redFsm->anyRegCurStateRef() )
		out << L", _ps";
	
	out << L";\n";
	out << L"	int _trans";

	if ( redFsm->anyConditions() )
		out << L", _cond";

	out << L";\n";

	out <<
		L"	" << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << L"_keys;\n"
		L"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << PTR_CONST_END() << POINTER() << L"_inds;\n";

	if ( redFsm->anyConditions() ) {
		out << 
			L"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxCond) << PTR_CONST_END() << POINTER() << L"_conds;\n"
			L"	" << WIDE_ALPH_TYPE() << L" _widec;\n";
	}

	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			L"	if ( " << P() << L" == " << PE() << L" )\n"
			L"		goto _test_eof;\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n"
			L"		goto _out;\n";
	}

	out << L"_resume:\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			L"	switch ( " << FSA() << L"[" << vCS() << L"] ) {\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

	if ( redFsm->anyConditions() )
		COND_TRANSLATE();

	LOCATE_TRANS();

	if ( redFsm->anyEofTrans() )
		out << L"_eof_trans:\n";
	
	if ( redFsm->anyRegCurStateRef() )
		out << L"	_ps = " << vCS() << L";\n";

	out << 
		L"	" << vCS() << L" = " << TT() << L"[_trans];\n\n";

	if ( redFsm->anyRegActions() ) {
		out << 
			L"	if ( " << TA() << L"[_trans] == 0 )\n"
			L"		goto _again;\n"
			L"\n"
			L"	switch ( " << TA() << L"[_trans] ) {\n";
			ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

	if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
			redFsm->anyActionCalls() || redFsm->anyActionRets() )
		out << L"_again:\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			L"	switch ( " << TSA() << L"[" << vCS() << L"] ) {\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	}\n"
			L"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	if ( " << vCS() << L" == " << redFsm->errState->id << L" )\n"
			L"		goto _out;\n";
	}

	if ( !noEnd ) {
		out << 
			L"	if ( ++" << P() << L" != " << PE() << L" )\n"
			L"		goto _resume;\n";
	}
	else {
		out << 
			L"	" << P() << L" += 1;\n"
			L"	goto _resume;\n";
	}

	if ( testEofUsed )
		out << L"	_test_eof: {}\n";

	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out <<
			L"	if ( " << P() << L" == " << vEOF() << L" )\n"
			L"	{\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				L"	if ( " << ET() << L"[" << vCS() << L"] > 0 ) {\n"
				L"		_trans = " << ET() << L"[" << vCS() << L"] - 1;\n"
				L"		goto _eof_trans;\n"
				L"	}\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				L"	switch ( " << EA() << L"[" << vCS() << L"] ) {\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				L"	}\n";
		}

		out <<
			L"	}\n"
			L"\n";
	}

	if ( outLabelUsed )
		out << L"	_out: {}\n";

	out << L"	}\n";
}
Example #28
0
void CSharpFlatCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;
	initVarTypes();

	out << 
		"	{\n"
		"	" << slenType << " _slen";

	if ( redFsm->anyRegCurStateRef() )
		out << ", _ps";

	out << 
		";\n"
		"	" << transType << " _trans";

	if ( redFsm->anyConditions() )
		out << ", _cond";
	out << ";\n";

	if ( redFsm->anyToStateActions() || 
			redFsm->anyRegActions() || redFsm->anyFromStateActions() )
	{
		out << 
			"	" << actsType << " _acts;\n"
			"	" << nactsType << " _nacts;\n"; 
	}

	out <<
		"	" << "int _keys;\n"
		"	" << indsType << " _inds;\n";
		/*
		"	" << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
		"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << "_inds;\n";*/

	if ( redFsm->anyConditions() ) {
		out << 
			"	" << condsType << " _conds;\n"
			"	" << WIDE_ALPH_TYPE() << " _widec;\n";
	}

	out << "\n";

	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			"	if ( " << P() << " == " << PE() << " )\n"
			"		goto _test_eof;\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	if ( " << vCS() << " == " << redFsm->errState->id << " )\n"
			"		goto _out;\n";
	}

	out << "_resume:\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			"	_acts = " << FSA() << "[" << vCS() << "];\n"
			"	_nacts = " << A() << "[_acts++];\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( " << A() << "[_acts++] ) {\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->anyConditions() )
		COND_TRANSLATE();

	LOCATE_TRANS();

	if ( redFsm->anyEofTrans() )
		out << "_eof_trans:\n";

	if ( redFsm->anyRegCurStateRef() )
		out << "	_ps = " << vCS() << ";\n";

	out <<
		"	" << vCS() << " = " << TT() << "[_trans];\n"
		"\n";

	if ( redFsm->anyRegActions() ) {
		out <<
			"	if ( " << TA() << "[_trans] == 0 )\n"
			"		goto _again;\n"
			"\n"
			"	_acts = " << TA() << "[_trans];\n"
			"	_nacts = " << A() << "[_acts++];\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( " << A() << "[_acts++] )\n		{\n";
			ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
			redFsm->anyActionCalls() || redFsm->anyActionRets() )
		out << "_again:\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			"	_acts = " << TSA() << "[" << vCS() << "];\n"
			"	_nacts = " << A() << "[_acts++];\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( " << A() << "[_acts++] ) {\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	if ( " << vCS() << " == " << redFsm->errState->id << " )\n"
			"		goto _out;\n";
	}

	if ( !noEnd ) {
		out << 
			"	if ( ++" << P() << " != " << PE() << " )\n"
			"		goto _resume;\n";
	}
	else {
		out << 
			"	" << P() << " += 1;\n"
			"	goto _resume;\n";
	}

	if ( testEofUsed )
		out << "	_test_eof: {}\n";

	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out << 
			"	if ( " << P() << " == " << vEOF() << " )\n"
			"	{\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				"	if ( " << ET() << "[" << vCS() << "] > 0 ) {\n"
				"		_trans = " << CAST(transType) << " (" << ET() << 
					"[" << vCS() << "] - 1);\n"
				"		goto _eof_trans;\n"
				"	}\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << 
						POINTER() << "__acts = " << 
						EA() << "[" << vCS() << "];\n"
				"	" << UINT() << " __nacts = " << CAST(UINT()) << " " <<
							A() << "[__acts++];\n"
				"	while ( __nacts-- > 0 ) {\n"
				"		switch ( " << A() << "[__acts++] ) {\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				"		}\n"
				"	}\n";
		}

		out <<
			"	}\n"
			"\n";
	}

	if ( outLabelUsed )
		out << "	_out: {}\n";

	out << "	}\n";
}
Example #29
0
void OCamlFFlatCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;
	initVarTypes();

	out << 
		L"	begin\n";
//		L"	" << slenType << L" _slen";

//	if ( redFsm->anyRegCurStateRef() )
//		out << L", _ps";
	
//	out << L";\n";
//	out << L"	" << transType << L" _trans";

//	if ( redFsm->anyConditions() )
//		out << L", _cond";

//	out << L";\n";

//	out <<
//		L"	" << L"int _keys;\n"
//		L"	" << indsType << L" _inds;\n";
		/*
		L"	" << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << L"_keys;\n"
		L"	" << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << L"_inds;\n";*/

  out <<
    L"	let state = { keys = 0; trans = 0; } in\n"
    L"	let rec do_start () =\n";

//	if ( redFsm->anyConditions() ) {
//		out << 
//			L"	" << condsType << L" _conds;\n"
//			L"	" << WIDE_ALPH_TYPE() << L" _widec;\n";
//	}

	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			L"	if " << P() << L" = " << PE() << L" then\n"
			L"		do_test_eof ()\n"
      L"\telse\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	if " << vCS() << L" = " << redFsm->errState->id << L" then\n"
			L"		do_out ()\n"
      L"\telse\n";
	}
  out << L"\tdo_resume ()\n";

	out << L"and do_resume () =\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			L"	begin match " << AT( FSA(), vCS() ) << L" with\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	end;\n"
			L"\n";
	}

	if ( redFsm->anyConditions() )
		COND_TRANSLATE();

  out << L"\tbegin try\n";
	LOCATE_TRANS();
  out << L"\twith Goto_match -> () end;\n";

  out << L"\tdo_eof_trans ()\n";
	
//	if ( redFsm->anyEofTrans() )
  out << L"and do_eof_trans () =\n";

	if ( redFsm->anyRegCurStateRef() )
		out << L"	let ps = " << vCS() << L" in\n";

	out <<
		L"	" << vCS() << L" <- " << AT( TT() ,L"state.trans" ) << L";\n"
		L"\n";

	if ( redFsm->anyRegActions() ) {
		out << 
			L"	begin try if " << AT( TA() , L"state.trans" ) << L" = 0 then\n"
			L"		raise Goto_again;\n"
			L"\n"
			L"	match " << AT( TA(), L"state.trans" ) << L" with\n";
			ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	with Goto_again -> () end;\n"
			L"\n";
	}
  out << L"\tdo_again ()\n";

//	if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
//			redFsm->anyActionCalls() || redFsm->anyActionRets() )
  out << L"\tand do_again () =\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			L"	begin match " << AT( TSA(), vCS() ) << L" with\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			L"	end;\n"
			L"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			L"	match " << vCS() << L" with\n"
      L"\t| " << redFsm->errState->id << L" -> do_out ()\n"
      L"\t| _ ->\n";
	}

  out << L"\t" << P() << L" <- " << P() << L" + 1;\n";

	if ( !noEnd ) {
		out << 
			L"	if " << P() << L" <> " << PE() << L" then\n"
			L"		do_resume ()\n"
      L"\telse do_test_eof ()\n";
	}
	else {
		out << 
			L"	do_resume ()\n";
	}

//	if ( testEofUsed )
	out << L"and do_test_eof () =\n";
	
	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out << 
			L"	if " << P() << L" = " << vEOF() << L" then\n"
			L"	begin try\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				L"	if " << AT( ET(), vCS() ) << L" > 0 then\n"
				L"	begin\n"
        L"   state.trans <- " << CAST(transType) << L"(" << AT( ET(), vCS() ) << L" - 1);\n"
				L"		raise Goto_eof_trans;\n"
				L"	end;\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				L"	begin match " << AT( EA(), vCS() ) << L" with\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				L"	end\n";
		}

		out << 
			L"	with Goto_again -> do_again ()\n"
			L"	| Goto_eof_trans -> do_eof_trans () end\n"
			L"\n";
	}
  else
  {
    out << L"\t()\n";
  }

	if ( outLabelUsed )
		out << L"	and do_out () = ()\n";

  out << L"\tin do_start ()\n";
	out << L"	end;\n";
}
Example #30
0
void OCamlFGotoCodeGen::writeExec()
{
	testEofUsed = false;
	outLabelUsed = false;

	out << "	begin\n";

	if ( redFsm->anyRegCurStateRef() )
		out << "	let _ps = ref 0 in\n";

	if ( redFsm->anyConditions() )
		out << "	let _widec : " << WIDE_ALPH_TYPE() << " = ref 0 in\n";

	out << "\n";
  out << "\tlet rec do_start () =\n";
	if ( !noEnd ) {
		testEofUsed = true;
		out << 
			"	if " << P() << " = " << PE() << " then\n"
			"		do_test_eof ()\n"
      "\telse\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	if " << vCS() << " = " << redFsm->errState->id << " then\n"
			"		do_out ()\n"
      "\telse\n";
	}
  out << "\tdo_resume ()\n";

	out << "and do_resume () =\n";

	if ( redFsm->anyFromStateActions() ) {
		out <<
			"	begin match " << AT(FSA(),vCS()) << " with\n";
			FROM_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"	end;\n"
			"\n";
	}

	out << 
		"	begin match " << vCS() << " with\n";
		STATE_GOTOS();
		SWITCH_DEFAULT() <<
		"	end\n"
		"\n";
		TRANSITIONS() << 
		"\n";

	if ( redFsm->anyRegActions() )
		EXEC_ACTIONS() << "\n";

	out << "\tand do_again () =\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			" begin match " << AT(TSA(), vCS()) << " with\n";
			TO_STATE_ACTION_SWITCH();
			SWITCH_DEFAULT() <<
			"	end;\n"
			"\n";
	}

	if ( redFsm->errState != 0 ) {
		outLabelUsed = true;
		out << 
			"	match " << vCS() << " with\n" <<
      "	| " << redFsm->errState->id << " -> do_out ()\n"
      "	| _ ->\n";
	}

	out << "\t" << P() << " <- " << P() << " + 1;\n";

	if ( !noEnd ) {
		out << 
			"	if " << P() << " <> " << PE() << " then\n"
			"		do_resume ()\n"
      "\telse do_test_eof ()\n";
	}
	else {
		out << 
			"	do_resume ()\n";
	}

//	if ( testEofUsed )
  out << "and do_test_eof () =\n";

	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out <<
			"	if " << P() << " = " << vEOF() << " then\n"
			"	begin\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				"	match " << vCS() << " with\n";

			for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
				if ( st->eofTrans != 0 )
					out << "	| " << st->id << " -> tr" << st->eofTrans->id << " ()\n";
			}

			SWITCH_DEFAULT() << ";\n"; // fall through
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				"	try match " << AT(EA(), vCS()) << " with\n";
				EOF_ACTION_SWITCH();
				SWITCH_DEFAULT() <<
				"	\n"
				"	with Goto_again -> do_again () \n";
		}

		out <<
			"	end\n"
			"\n";
	}
  else
    out << "\t()\n";

	if ( outLabelUsed )
		out << "\tand do_out () = ()\n";

  out << "\tin do_start ()\n";
	out << "	end;\n";
}