예제 #1
0
파일: service.cpp 프로젝트: ljr/mm1k
void Service::Display ()
  {
  int srvr_i;
  for (srvr_i = 0; srvr_i < num_srvrs; srvr_i++)
     cout << '(' << setw(2) << srvr_i << ')'
          << " TK " << setw(3) << GetTokenID (srvr_i)
          << " PR " << setw(2) << GetPri     (srvr_i) << ' ';
  }
예제 #2
0
static JILError GetToken(JCLFile* _this, JCLString* pToken, JILLong* pTokenID)
{
	JILError err = JCL_No_Error;
	JILChar c;
	JILChar d;

	// clear output string
	*pTokenID = tk_unknown;
	JCLClear(pToken);

	// check what we have found
	c = JCLGetCurrentChar(_this->mipText);
	d = JCLGetChar(_this->mipText, JCLGetLocator(_this->mipText) + 1);
	// verbatim string literal?
	if( (c == '/' || c == '@') && d == '\"' )
	{
		// read the entire string literal
		err = GetStrLiteral(_this, pToken);
		*pTokenID = tk_lit_string;
	}
	// part of keyword or identifier characters?
	else if( IsCharType(c, kKeywordChars) )
	{
		// try to read as many characters of the keyword or identifier
		JCLSpanIncluding(_this->mipText, kIdentifierChars, pToken);
		// check if it is a keyword
		*pTokenID = GetTokenID(JCLGetString(pToken), kKeywordList);
		// check err
		if( *pTokenID == tk_unknown )
			*pTokenID = tk_identifier;
	}
	// part of operator characters?
	else if( IsCharType(c, kOperatorChars) && (c != '.' || !IsDigit(d)) )
	{
		// try to find a matching operator token
		err = FindTokenAtPosition(_this, pToken, pTokenID, kOperatorList);
	}
	// part of number characters?
	else if( IsCharType(c, kFirstDigitChars) && (c != '.' || IsDigit(d)) )
	{
		JILLong type;
		// check if long or float number, scan in the token and return tk_lit_int or tk_lit_float!
		JCLSpanNumber(_this->mipText, pToken, &type);
		*pTokenID = (type || _this->mipOptions->miDefaultFloat) ? tk_lit_float : tk_lit_int;
	}
	else if( IsCharType(c, kCharacterChars) )
	{
		// try to read as many characters as possible
		JCLSpanIncluding(_this->mipText, kCharacterChars, pToken);
		// try to find the character in the list
		*pTokenID = GetTokenID(JCLGetString(pToken), kCharacterList);
		// check err
		if( *pTokenID == tk_unknown )
			err = JCL_ERR_Unexpected_Token;
	}
	else if( IsCharType(c, kSingleChars) )
	{
		// must read only a single character
		JCLFill(pToken, JCLGetCurrentChar(_this->mipText), 1);
		JCLSeekForward(_this->mipText, 1);
		// try to find the character in the list
		*pTokenID = GetTokenID(JCLGetString(pToken), kCharacterList);
		// check err
		if( *pTokenID == tk_unknown )
			err = JCL_ERR_Unexpected_Token;
	}
	else
	{
		// single characters
		switch( c )
		{
			case '\"':
				// read the entire string literal
				err = GetStrLiteral(_this, pToken);
				*pTokenID = tk_lit_string;
				break;
			case '\'':
				// read the entire character literal
				err = GetStrLiteral(_this, pToken);
				*pTokenID = tk_lit_char;
				break;
			default:
				err = JCL_ERR_Unexpected_Token;
				break;
		}
	}
	return err;
}