Beispiel #1
0
void CPage::loadPhraseCheck(ConnectionPtr connection)
{
	Trace("loadPhraseCheck()", "", 0);

	std::string strQuery;

	try
	{
		Mutex::Lock lock(m_phraseListLock);

		strQuery = Format(SQL_WTT_PHRASE_WORDS, getPageID());
		if (ResultPtr result = connection->Query(strQuery))
		{
			Trace("RowPtr s:","",result->GetRowCount());

			while (result->Next())
			{
				RowPtr row = result->GetCurrentRow();

				StringIDList::value_type phrase(row->GetFieldString(1), row->GetFieldLong(2));

				Trace("loadPhraseCheck_LT(): pre", phrase.first.c_str(), phrase.second);
				std::transform(phrase.first.begin(), phrase.first.end(), phrase.first.begin(), tolower);
				Trace("loadPhraseCheck_LT(): post", phrase.first.c_str(), phrase.second);
				m_phrase.push_back(phrase);
			}
		}
	}
	catch (const std::exception& e)
	{
		LogError("Exception Caught:", e.what(), 0);
	}
}
Beispiel #2
0
void ConstrainedDecoding::Load()
{
  const StaticData &staticData = StaticData::Instance();
  bool addBeginEndWord = (staticData.GetSearchAlgorithm() == ChartDecoding) || (staticData.GetSearchAlgorithm() == ChartIncremental);

  InputFileStream constraintFile(m_path);
  std::string line;
  long sentenceID = staticData.GetStartTranslationId() - 1;
  while (getline(constraintFile, line)) {
    vector<string> vecStr = Tokenize(line, "\t");

    Phrase phrase(0);
    if (vecStr.size() == 1) {
      sentenceID++;
      phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[0], staticData.GetFactorDelimiter(), NULL);
    } else if (vecStr.size() == 2) {
      sentenceID = Scan<long>(vecStr[0]);
      phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[1], staticData.GetFactorDelimiter(), NULL);
    } else {
      UTIL_THROW(util::Exception, "Reference file not loaded");
    }

    if (addBeginEndWord) {
      phrase.InitStartEndWord();
    }
    m_constraints.insert(make_pair(sentenceID,phrase));

  }
}
Beispiel #3
0
void RSDialog::filterRS(const QList<int>& r, const QList<int>& s)
{
    QString string("<qt>");

    if (r.count() > 0) {
        string.append("<h2>" + i18n("R-Phrases:") + "</h2>");
        foreach (int i, r) {
            QString phrase("<b>" + QString::number(i) + " - ");
            phrase.append(rphrase(i) + "</b>");
            string.append(phrase + "<br>");
        }
Beispiel #4
0
/*
 * Advances the lexer one token forward, returning true if one exists
 */
bool lexer::next(void) {

	// remove whitespace from stream
	remove_whitespace();
	text.clear();

	// Parse next character in stream to determine the tokens likely type
	if(!buff.has_next())
		type = token::END;
	else if(isdigit(buff.get_current()))
		number();
	else if(isalpha(buff.get_current()))
		phrase();
	else
		symbol();
	return true;
}
/*
 * Update history with a batch of translations
 */
void BleuScoreFeature::UpdateHistory(const vector< vector< const Word* > >& hypos, vector<size_t>& sourceLengths, vector<size_t>& ref_ids, size_t rank, size_t epoch)
{
    for (size_t ref_id = 0; ref_id < hypos.size(); ++ref_id) {
        Phrase phrase(hypos[ref_id]);
        std::vector< size_t > ngram_counts(BleuScoreState::bleu_order);
        std::vector< size_t > ngram_matches(BleuScoreState::bleu_order);

        // set current source and reference information for each oracle in the batch
        size_t cur_source_length = sourceLengths[ref_id];
        size_t hypo_length = hypos[ref_id].size();
        size_t cur_ref_length = GetClosestRefLength(ref_ids[ref_id], hypo_length);
        NGrams cur_ref_ngrams = m_refs[ref_ids[ref_id]].second;
        cerr << "reference length: " << cur_ref_length << endl;

        // compute vector c(e;{r_k}):
        // vector of effective reference length, number of ngrams in e, number of ngram matches between e and r_k
        GetNgramMatchCounts(phrase, cur_ref_ngrams, ngram_counts, ngram_matches, 0);

        // update counts and matches for every ngram length with counts from hypo
        for (size_t i = 0; i < BleuScoreState::bleu_order; i++) {
            m_count_history[i] += ngram_counts[i];
            m_match_history[i] += ngram_matches[i];

            // do this for last position in batch
            if (ref_id == hypos.size() - 1) {
                m_count_history[i] *= m_historySmoothing;
                m_match_history[i] *= m_historySmoothing;
            }
        }

        // update counts for reference and target length
        m_source_length_history += cur_source_length;
        m_target_length_history += hypos[ref_id].size();
        m_ref_length_history += cur_ref_length;

        // do this for last position in batch
        if (ref_id == hypos.size() - 1) {
            cerr << "Rank " << rank << ", epoch " << epoch << " ,source length history: " << m_source_length_history << " --> " << m_source_length_history * m_historySmoothing << endl;
            cerr << "Rank " << rank << ", epoch " << epoch << " ,target length history: " << m_target_length_history << " --> " << m_target_length_history * m_historySmoothing << endl;
            m_source_length_history *= m_historySmoothing;
            m_target_length_history *= m_historySmoothing;
            m_ref_length_history *= m_historySmoothing;
        }
    }
}
Beispiel #6
0
// query_word -> word | phrase
static syntree *query_word (token **lookahead, err_context context)
{
	syntree *node = NULL;
	RETURN_NULL_IF_OVER_DEPTH_LIMIT(context);

	if (ft_test (lookahead, TOK_FT_PHRASE))
	{
		return (phrase (lookahead, context));
	}
	else if (ft_test (lookahead, TOK_FT_WORD))
	{
		node = (syntree *) ft_word_new ((*lookahead)->lexeme->contents);
		if (node)
		{
			advance (lookahead);
		}
	}

	return (node);
}
/*
 * Update the pseudo-document O after each translation of a source sentence.
 * (O is an exponentially-weighted moving average of vectors c(e;{r_k}))
 * O = m_historySmoothing * (O + c(e_oracle))
 * O_f = m_historySmoothing * (O_f + |f|)		input length of pseudo-document
 */
void BleuScoreFeature::UpdateHistory(const vector< const Word* >& hypo)
{
    Phrase phrase(hypo);
    std::vector< size_t > ngram_counts(BleuScoreState::bleu_order);
    std::vector< size_t > ngram_matches(BleuScoreState::bleu_order);

    // compute vector c(e;{r_k}):
    // vector of effective reference length, number of ngrams in e, number of ngram matches between e and r_k
    GetNgramMatchCounts(phrase, m_cur_ref_ngrams, ngram_counts, ngram_matches, 0);

    // update counts and matches for every ngram length with counts from hypo
    for (size_t i = 0; i < BleuScoreState::bleu_order; i++) {
        m_count_history[i] = m_historySmoothing * (m_count_history[i] + ngram_counts[i]);
        m_match_history[i] = m_historySmoothing * (m_match_history[i] + ngram_matches[i]);
    }

    // update counts for reference and target length
    m_source_length_history = m_historySmoothing * (m_source_length_history + m_cur_source_length);
    m_target_length_history = m_historySmoothing * (m_target_length_history + hypo.size());
    m_ref_length_history = m_historySmoothing * (m_ref_length_history + m_cur_ref_length);
}
Beispiel #8
0
static int
blk_full(MACRO_PROT_ARGS)
{
	int		  la, nl, nparsed;
	struct mdoc_arg	 *arg;
	struct mdoc_node *head; /* save of head macro */
	struct mdoc_node *body; /* save of body macro */
	struct mdoc_node *n;
	enum mdoc_type	  mtt;
	enum mdoct	  ntok;
	enum margserr	  ac, lac;
	enum margverr	  av;
	char		 *p;

	nl = MDOC_NEWLINE & m->flags;

	/* Close out prior implicit scope. */

	if ( ! (MDOC_EXPLICIT & mdoc_macros[tok].flags)) {
		if ( ! rew_sub(MDOC_BODY, m, tok, line, ppos))
			return(0);
		if ( ! rew_sub(MDOC_BLOCK, m, tok, line, ppos))
			return(0);
	}

	/*
	 * This routine accommodates implicitly- and explicitly-scoped
	 * macro openings.  Implicit ones first close out prior scope
	 * (seen above).  Delay opening the head until necessary to
	 * allow leading punctuation to print.  Special consideration
	 * for `It -column', which has phrase-part syntax instead of
	 * regular child nodes.
	 */

	for (arg = NULL;; ) {
		la = *pos;
		av = mdoc_argv(m, line, tok, &arg, pos, buf);

		if (ARGV_WORD == av) {
			*pos = la;
			break;
		} 

		if (ARGV_EOLN == av)
			break;
		if (ARGV_ARG == av)
			continue;

		mdoc_argv_free(arg);
		return(0);
	}

	if ( ! mdoc_block_alloc(m, line, ppos, tok, arg))
		return(0);

	head = body = NULL;

	/*
	 * Exception: Heads of `It' macros in `-diag' lists are not
	 * parsed, even though `It' macros in general are parsed.
	 */
	nparsed = MDOC_It == tok &&
		MDOC_Bl == m->last->parent->tok &&
		LIST_diag == m->last->parent->norm->Bl.type;

	/*
	 * The `Nd' macro has all arguments in its body: it's a hybrid
	 * of block partial-explicit and full-implicit.  Stupid.
	 */

	if (MDOC_Nd == tok) {
		if ( ! mdoc_head_alloc(m, line, ppos, tok))
			return(0);
		head = m->last;
		if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos))
			return(0);
		if ( ! mdoc_body_alloc(m, line, ppos, tok))
			return(0);
		body = m->last;
	} 

	ac = ARGS_ERROR;

	for ( ; ; ) {
		la = *pos;
		/* Initialise last-phrase-type with ARGS_PEND. */
		lac = ARGS_ERROR == ac ? ARGS_PEND : ac;
		ac = mdoc_args(m, line, pos, buf, tok, &p);

		if (ARGS_PUNCT == ac)
			break;

		if (ARGS_ERROR == ac)
			return(0);

		if (ARGS_EOLN == ac) {
			if (ARGS_PPHRASE != lac && ARGS_PHRASE != lac)
				break;
			/*
			 * This is necessary: if the last token on a
			 * line is a `Ta' or tab, then we'll get
			 * ARGS_EOLN, so we must be smart enough to
			 * reopen our scope if the last parse was a
			 * phrase or partial phrase.
			 */
			if ( ! rew_sub(MDOC_BODY, m, tok, line, ppos))
				return(0);
			if ( ! mdoc_body_alloc(m, line, ppos, tok))
				return(0);
			body = m->last;
			break;
		}

		/* 
		 * Emit leading punctuation (i.e., punctuation before
		 * the MDOC_HEAD) for non-phrase types.
		 */

		if (NULL == head && 
				ARGS_PEND != ac &&
				ARGS_PHRASE != ac &&
				ARGS_PPHRASE != ac &&
				ARGS_QWORD != ac &&
				DELIM_OPEN == mdoc_isdelim(p)) {
			if ( ! dword(m, line, la, p, DELIM_OPEN))
				return(0);
			continue;
		}

		/* Open a head if one hasn't been opened. */

		if (NULL == head) {
			if ( ! mdoc_head_alloc(m, line, ppos, tok))
				return(0);
			head = m->last;
		}

		if (ARGS_PHRASE == ac || 
				ARGS_PEND == ac ||
				ARGS_PPHRASE == ac) {
			/*
			 * If we haven't opened a body yet, rewind the
			 * head; if we have, rewind that instead.
			 */

			mtt = body ? MDOC_BODY : MDOC_HEAD;
			if ( ! rew_sub(mtt, m, tok, line, ppos))
				return(0);
			
			/* Then allocate our body context. */

			if ( ! mdoc_body_alloc(m, line, ppos, tok))
				return(0);
			body = m->last;

			/*
			 * Process phrases: set whether we're in a
			 * partial-phrase (this effects line handling)
			 * then call down into the phrase parser.
			 */

			if (ARGS_PPHRASE == ac)
				m->flags |= MDOC_PPHRASE;
			if (ARGS_PEND == ac && ARGS_PPHRASE == lac)
				m->flags |= MDOC_PPHRASE;

			if ( ! phrase(m, line, la, buf))
				return(0);

			m->flags &= ~MDOC_PPHRASE;
			continue;
		}

		ntok = nparsed || ARGS_QWORD == ac ? 
			MDOC_MAX : lookup(tok, p);

		if (MDOC_MAX == ntok) {
			if ( ! dword(m, line, la, p, DELIM_MAX))
				return(0);
			continue;
		}

		if ( ! mdoc_macro(m, ntok, line, la, pos, buf))
			return(0);
		break;
	}

	if (NULL == head) {
		if ( ! mdoc_head_alloc(m, line, ppos, tok))
			return(0);
		head = m->last;
	}
	
	if (nl && ! append_delims(m, line, pos, buf))
		return(0);

	/* If we've already opened our body, exit now. */

	if (NULL != body)
		goto out;

	/*
	 * If there is an open (i.e., unvalidated) sub-block requiring
	 * explicit close-out, postpone switching the current block from
	 * head to body until the rew_sub() call closing out that
	 * sub-block.
	 */
	for (n = m->last; n && n != head; n = n->parent) {
		if (MDOC_BLOCK == n->type && 
				MDOC_EXPLICIT & mdoc_macros[n->tok].flags &&
				! (MDOC_VALID & n->flags)) {
			n->pending = head;
			return(1);
		}
	}

	/* Close out scopes to remain in a consistent state. */

	if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos))
		return(0);
	if ( ! mdoc_body_alloc(m, line, ppos, tok))
		return(0);

out:
	if ( ! (MDOC_FREECOL & m->flags))
		return(1);

	if ( ! rew_sub(MDOC_BODY, m, tok, line, ppos))
		return(0);
	if ( ! rew_sub(MDOC_BLOCK, m, tok, line, ppos))
		return(0);

	m->flags &= ~MDOC_FREECOL;
	return(1);
}
Beispiel #9
0
char *
skin(char *name)
{
	return phrase(name, 0, 0);
}
Beispiel #10
0
void parse_msr( void )
{
	while ( 1 ) {
		int f;
		char *p = gettoken( &f );
		//char a;
		if ( !p ) break;
		//a = *p;
		if ( f & TT_LABEL ) {
			int n = strlen(p);
			if ( p[n-1] == ':' ) p[n-1] = 0;
			RegLabel( p );
		}
		else if ( f & TT_NUMBER ) {
			cgout1( getnum( p ) );
		}
		else if ( f & TT_STRING ) {
			int i, n = strlen( p );
			if ( n > 2 && p[0] == p[n-1] ) n--;
			for ( i = 1; i < n; i++ ) cgout1( p[i] );
		}
		else if ( f & TT_OTHER ) {
			HASHDATA *phd = SearchHash( p );
			if ( phd ) {
				if ( phd->type == TYPE_RESERVED )
					switch ( phd->value ) {
						case RSV_ADRS:
							adrs();
							break;
						case RSV_ADRSM:
							adrsm();
							break;
						case RSV_ADRSD:
							adrsd();
							break;
						case RSV_INCLUDE:
							include();
							break;
						case RSV_GOTO:
							_goto();
							break;
						case RSV_TEMPO:
							tempo();
							break;
						case RSV_PARTN:
							partn();
							break;
						case RSV_PHRASE:
							phrase();
							break;
				}
				else if ( phd->type & TYPE_DIRECTCODE ) {
					cgout1( phd->value );
				}
			}
			else {
				error( "Unkown commands '%s'.", p );
			}
		}
		else if ( f & TT_MML ) {
			parse_mml_line( -1, p );
		}
	}
}
Beispiel #11
0
//--------------------------------------------------------------------------
int ana(void)
{
  int code = ua_next_byte();
  int saved_code = code;
  char dtyp = dt_byte;
  if ( code < 0x60 )
  {
    cmd.itype = A2[code];
  }
  else
  {
    if ( code & 8 )
    {
      cmd.auxpref |= aux_word;
      dtyp = dt_word;
    }
    else
    {
      cmd.auxpref |= aux_byte;
      dtyp = dt_byte;
    }
    cmd.itype = A2tail[(code>>4)-6];
  }
  if ( cmd.itype == H8500_null ) return 0;
  switch ( code )
  {
    case 0x02:  // ldm.w @sp+, <reglist>
//      cmd.auxpref |= aux_word;
      phrase(cmd.Op1, SP, ph_post, dt_word);
      cmd.Op2.type = o_reglist;
      cmd.Op2.reg  = ua_next_byte();
      if ( !cmd.Op2.reg ) return 0;
      break;
    case 0x12:  // stm.w <reglist>, @-sp
//      cmd.auxpref |= aux_word;
      cmd.Op1.type = o_reglist;
      cmd.Op1.reg  = ua_next_byte();
      if ( !cmd.Op1.reg ) return 0;
      phrase(cmd.Op2, SP, ph_pre, dt_word);
      break;
    case 0x01:  // scb/f
      cmd.auxpref |= aux_f;
      break;
    case 0x06:  // scb/ne
      cmd.auxpref |= aux_ne;
      break;
    case 0x07:  // scb/eq
      cmd.auxpref |= aux_eq;
      break;
    case 0x08:  // trapa #xx
      code = ua_next_byte();
      if ( (code & 0xF0) != 0x10 ) return 0;
      cmd.Op1.type = o_imm;
      cmd.Op1.dtyp = dt_byte;
      cmd.Op1.value = code & 15;
      break;
    case 0x0F:  // unlk
      reg(cmd.Op1, FP, dt_word);
      break;
    case 0x10:  // jmp @aa:16
    case 0x18:  // jsr @aa:16
      aa16(cmd.Op1, dt_code);
      cmd.Op1.type = o_near;
      cmd.Op1.addr += cmd.ea & ~0xFFFF;
      break;
    case 0x17:  // link #xx:8
      reg(cmd.Op1, FP, dt_word);
      imm8(cmd.Op2);
      break;
    case 0x1F:  // link #xx:16
      reg(cmd.Op1, FP, dt_word);
      imm16(cmd.Op2);
      break;
    case 0x03:  // pjsr @aa:24
    case 0x13:  // pjmp @aa:24
      {
        cmd.auxpref |= aux_disp24;
        uint32 page   = ua_next_byte();
        cmd.Op1.type = o_far;
        cmd.Op1.dtyp = dt_code;
        cmd.Op1.addr = (page<<16) | ua_next_word();
      }
      break;
    case 0x04:  // #xx:8
      cmd.auxpref |= aux_byte;
    case 0x14:  // #xx:8
      imm8(cmd.Op1);
      break;
    case 0x05:  // #aa:8.B
      cmd.auxpref |= aux_byte;
      aa8(cmd.Op1, dt_byte);
      break;
    case 0x15:  // #aa:16.B
      cmd.auxpref |= aux_byte;
      aa16(cmd.Op1, dt_byte);
      break;
    case 0x0C:  // #xx:16
      cmd.auxpref |= aux_word;
    case 0x1C:  // #xx:16
      imm16(cmd.Op1);
      break;
    case 0x0D:  // #aa:8.W
      cmd.auxpref |= aux_word;
      aa8(cmd.Op1, dt_word);
      dtyp = dt_word;
      break;
    case 0x1D:  // #aa:16.W
      cmd.auxpref |= aux_word;
      aa16(cmd.Op1, dt_word);
      dtyp = dt_word;
      break;
    case 0x0E:                                  // bsr d:8
    case 0x20: case 0x21: case 0x22: case 0x23: // d:8
    case 0x24: case 0x25: case 0x26: case 0x27:
    case 0x28: case 0x29: case 0x2A: case 0x2B:
    case 0x2C: case 0x2D: case 0x2E: case 0x2F:
      d8(cmd.Op1);
      break;
    case 0x1E:                                  // bsr d:16
    case 0x30: case 0x31: case 0x32: case 0x33: // d:16
    case 0x34: case 0x35: case 0x36: case 0x37:
    case 0x38: case 0x39: case 0x3A: case 0x3B:
    case 0x3C: case 0x3D: case 0x3E: case 0x3F:
      {
        cmd.auxpref |= aux_disp16;
        int32 disp = short(ua_next_word());
        cmd.Op1.type = o_near;
        cmd.Op1.dtyp = dt_code;
        cmd.Op1.addr = cmd.ip + cmd.size + disp;
      }
      break;
    case 0x40: case 0x41: case 0x42: case 0x43: // cmp:e #xx:8, Rn
    case 0x44: case 0x45: case 0x46: case 0x47:
    case 0x50: case 0x51: case 0x52: case 0x53: // mov:e #xx:8, Rn
    case 0x54: case 0x55: case 0x56: case 0x57:
      cmd.auxpref |= aux_byte;
      imm8(cmd.Op1);
      reg(cmd.Op2, code, dtyp);
      break;
    case 0x48: case 0x49: case 0x4A: case 0x4B: // cmp:i #xx:16, Rn
    case 0x4C: case 0x4D: case 0x4E: case 0x4F:
    case 0x58: case 0x59: case 0x5A: case 0x5B: // mov:i #xx:16, Rn
    case 0x5C: case 0x5D: case 0x5E: case 0x5F:
      cmd.auxpref |= aux_word;
      imm16(cmd.Op1);
      reg(cmd.Op2, code, dtyp);
      break;
    case 0x60: case 0x61: case 0x62: case 0x63: // @aa:8, Rn
    case 0x64: case 0x65: case 0x66: case 0x67:
    case 0x68: case 0x69: case 0x6A: case 0x6B:
    case 0x6C: case 0x6D: case 0x6E: case 0x6F:
      aa8(cmd.Op1, dtyp);
      reg(cmd.Op2, code, dtyp);
      break;
    case 0x70: case 0x71: case 0x72: case 0x73: // Rn, @aa:8
    case 0x74: case 0x75: case 0x76: case 0x77:
    case 0x78: case 0x79: case 0x7A: case 0x7B:
    case 0x7C: case 0x7D: case 0x7E: case 0x7F:
      reg(cmd.Op1, code, dtyp);
      aa8(cmd.Op2, dtyp);
      break;
    case 0x80: case 0x81: case 0x82: case 0x83: // mov:f @(d:8, R6), Rn
    case 0x84: case 0x85: case 0x86: case 0x87:
    case 0x88: case 0x89: case 0x8A: case 0x8B:
    case 0x8C: case 0x8D: case 0x8E: case 0x8F:
      ds8(cmd.Op1, R6, dtyp);
      reg(cmd.Op2, code, dtyp);
      break;
    case 0x90: case 0x91: case 0x92: case 0x93: // mov:f Rn, @(d:8, R6)
    case 0x94: case 0x95: case 0x96: case 0x97:
    case 0x98: case 0x99: case 0x9A: case 0x9B:
    case 0x9C: case 0x9D: case 0x9E: case 0x9F:
      reg(cmd.Op1, code, dtyp);
      ds8(cmd.Op2, R6, dtyp);
      break;
    case 0xA0: case 0xA1: case 0xA2: case 0xA3: // Rn, Rn
    case 0xA4: case 0xA5: case 0xA6: case 0xA7:
    case 0xA8: case 0xA9: case 0xAA: case 0xAB:
    case 0xAC: case 0xAD: case 0xAE: case 0xAF:
      reg(cmd.Op1, code, dtyp);
      break;
    case 0xB0: case 0xB1: case 0xB2: case 0xB3: // @-Rn, Rn
    case 0xB4: case 0xB5: case 0xB6: case 0xB7:
    case 0xB8: case 0xB9: case 0xBA: case 0xBB:
    case 0xBC: case 0xBD: case 0xBE: case 0xBF:
      phrase(cmd.Op1, code, ph_pre, dtyp);
      break;
    case 0xC0: case 0xC1: case 0xC2: case 0xC3: // @Rn+, Rn
    case 0xC4: case 0xC5: case 0xC6: case 0xC7:
    case 0xC8: case 0xC9: case 0xCA: case 0xCB:
    case 0xCC: case 0xCD: case 0xCE: case 0xCF:
      phrase(cmd.Op1, code, ph_post, dtyp);
      break;
    case 0xD0: case 0xD1: case 0xD2: case 0xD3: // @Rn, Rn
    case 0xD4: case 0xD5: case 0xD6: case 0xD7:
    case 0xD8: case 0xD9: case 0xDA: case 0xDB:
    case 0xDC: case 0xDD: case 0xDE: case 0xDF:
      phrase(cmd.Op1, code, ph_normal, dtyp);
      break;
    case 0xE0: case 0xE1: case 0xE2: case 0xE3: // @(d:8,Rn), Rn
    case 0xE4: case 0xE5: case 0xE6: case 0xE7:
    case 0xE8: case 0xE9: case 0xEA: case 0xEB:
    case 0xEC: case 0xED: case 0xEE: case 0xEF:
      ds8(cmd.Op1, code, dtyp);
      break;
    case 0xF0: case 0xF1: case 0xF2: case 0xF3: // @(d:16,Rn), Rn
    case 0xF4: case 0xF5: case 0xF6: case 0xF7:
    case 0xF8: case 0xF9: case 0xFA: case 0xFB:
    case 0xFC: case 0xFD: case 0xFE: case 0xFF:
      ds16(cmd.Op1, code, dtyp);
      break;
  }
  while ( cmd.itype > H8500_last )     // while MAPs are not resolved
  {
    int index = -(3+short(cmd.itype));
    if ( index < 0 || index >= qnumber(tables) ) interr("ana1");
    code = ua_next_byte();
    if ( code < 0x20 )
    {
      cmd.itype = tables[index].head[code];
    }
    else
    {
      cmd.itype = tables[index].tail[(code>>3)-4];
      reg(cmd.Op2, code, dtyp);
    }
    if ( index == 3 ) switch ( saved_code ) // MAP6
    {
      case 0x01:
      case 0x06:
      case 0x07:
        if ( cmd.itype != H8500_scb ) return 0;
        break;
      case 0x11:
        if ( cmd.itype != H8500_prts
          && cmd.itype != H8500_prtd
          && cmd.itype != H8500_jmp
          && cmd.itype != H8500_pjmp
          && cmd.itype != H8500_jsr
          && cmd.itype != H8500_pjsr ) return 0;
        break;
      default:
        if ( cmd.itype != H8500_movfpe
          && cmd.itype != H8500_movtpe
          && cmd.itype != H8500_dadd
          && cmd.itype != H8500_dsub ) return 0;
    }
    switch ( cmd.itype )
    {
      case H8500_null:
        return 0;
      case H8500_add_q:
        cmd.Op2 = cmd.Op1;
        switch ( code )
        {
          case 0x08: immv(cmd.Op1, 1);  break;
          case 0x09: immv(cmd.Op1, 2);  break;
          case 0x0C: immv(cmd.Op1, -1); break;
          case 0x0D: immv(cmd.Op1, -2); break;
        }
        break;
      case H8500_bset:
      case H8500_bclr:
      case H8500_bnot:
      case H8500_btst:
        cmd.Op2 = cmd.Op1;
        if ( code < 0xC0 )
          reg(cmd.Op1, code, dtyp);
        else
          immv(cmd.Op1, code & 15);
        break;
      case H8500_mov_g:
        if ( (code & 0xF8) == 0x80 ) break;
        cmd.Op2 = cmd.Op1;
        if ( code == 0x06 )
        {
          if ( (cmd.auxpref & aux_word) == 0 ) cmd.auxpref |= aux_byte;
          cmd.Op1.type  = o_imm;
          cmd.Op1.dtyp  = dt_byte;
          cmd.Op1.value = ua_next_byte();
        }
        else if ( code == 0x07 )
        {
          if ( (cmd.auxpref & aux_byte) == 0 ) cmd.auxpref |= aux_word;
          cmd.auxpref  |= aux_mov16;
          cmd.Op1.type  = o_imm;
          cmd.Op1.dtyp  = dt_word;
          cmd.Op1.value = ua_next_word();
        }
        else
          reg(cmd.Op1, code, dtyp);
        break;
      case H8500_cmp_g:
        if ( code > 5 ) break;
        cmd.Op2 = cmd.Op1;
        if ( code == 0x04 )
        {
          cmd.auxpref  |= aux_byte;
          cmd.Op1.type  = o_imm;
          cmd.Op1.dtyp  = dt_byte;
          cmd.Op1.value = ua_next_byte();
        }
        else
        {
          cmd.auxpref  |= aux_word;
          cmd.Op1.type  = o_imm;
          cmd.Op1.dtyp  = dt_word;
          cmd.Op1.value = ua_next_word();
        }
        break;
      case H8500_andc:
      case H8500_orc:
      case H8500_xorc:
      case H8500_ldc:
      case H8500_stc:
        cmd.Op2.reg += SR;
        if ( cmd.Op2.reg == RES1 || cmd.Op2.reg == CP ) return 0;
        if ( ((cmd.auxpref & aux_word) != 0) != (cmd.Op2.reg == SR) ) return 0;
        if ( cmd.itype != H8500_stc ) break;
        // no break
      case H8500_movtpe:
        {
          op_t x  = cmd.Op1;
          cmd.Op1 = cmd.Op2;
          cmd.Op2 = x;
        }
        break;
      case H8500_pjmp:
      case H8500_pjsr:
      case H8500_jmp:
      case H8500_jsr:
        cmd.Op2.type = o_void;
        switch ( code & 0xF0 )
        {
          case 0xC0:
          case 0xD0: phrase(cmd.Op1, code, ph_normal, dt_code); break;
          case 0xE0: ds8(cmd.Op1, code, dt_code); break;
          case 0xF0: ds16(cmd.Op1, code, dt_code); break;
        }
        break;
      case H8500_rtd:
      case H8500_prtd:
        if ( code == 0x14 )
          imm8(cmd.Op1);
        else
          imm16(cmd.Op1);
        break;
      case H8500_scb:
        cmd.Op1 = cmd.Op2;
        d8(cmd.Op2);
        break;
      case H8500_dadd:
      case H8500_dsub:
        if ( (cmd.auxpref & aux_byte) == 0 ) return 0;
        cmd.auxpref &= ~aux_byte;
        break;
    }
  }
  if ( (idpflags & AFIDP_MIXSIZE) == 0 ) // Disassemble mixed size instructions?
  {
    if ( (cmd.auxpref & aux_word) && cmd.Op1.dtyp == dt_byte
      || (cmd.auxpref & aux_byte) && cmd.Op1.dtyp == dt_word )
          if ( cmd.itype != H8500_mov_g ) return 0;
  }
  return cmd.size;
}