Beispiel #1
0
// ParseDirectives
// . Reads any directives that are next in the queue.
void Parser::ParseDirectives() {
  bool readDirective = false;

  while (1) {
    if (m_pScanner->empty())
      break;

    Token& token = m_pScanner->peek();
    if (token.type != Token::DIRECTIVE)
      break;

    // we keep the directives from the last document if none are specified;
    // but if any directives are specific, then we reset them
    if (!readDirective)
      m_pDirectives.reset(new Directives);

    readDirective = true;
    HandleDirective(token);
    m_pScanner->pop();
  }
}
Beispiel #2
0
CToken* CTokenizer::FetchToken()
{
	if (m_nextToken != NULL)
	{
		CToken* curToken = m_nextToken;
		m_nextToken = curToken->GetNext();
		curToken->SetNext(NULL);
		return curToken;
	}
	byte theByte;
	CToken* theToken = NULL;

	while (true)
	{
		if (!NextChar(theByte))
		{
			return CToken::Create();
		}
		if (theByte <= ' ')
		{
			if ((theByte == '\n') && ((TKF_USES_EOL & m_flags) != 0))
			{
				return CUserToken::Create(TK_EOL, "-EOLN-");
			}
			continue;
		}
		switch(theByte)
		{
		case '#':
			if ((m_flags & TKF_IGNOREDIRECTIVES) == 0)
			{
				theToken = HandleDirective();
			}
			else
			{
				if ((m_flags & TKF_NODIRECTIVES) != 0)
				{
					return HandleSymbol('#');
				}
				SkipToLineEnd();
			}
			break;
		case '/':
			theToken = HandleSlash();
			break;
		case '"':
			theToken = HandleString();
			break;
		case '\'':
			theToken = HandleQuote();
			break;
		default:
			if (((theByte >= 'a') && (theByte <= 'z'))
				|| ((theByte >= 'A') && (theByte <= 'Z'))
				|| ((theByte == '_') && ((m_flags & TKF_NOUNDERSCOREINIDENTIFIER) == 0)))
			{
				theToken = HandleIdentifier(theByte);
			}
			else if (((m_flags & TKF_NUMERICIDENTIFIERSTART) != 0) && (theByte >= '0') && (theByte <= '9'))
			{
				theToken = HandleIdentifier(theByte);
			}
			else if (((theByte >= '0') && (theByte <= '9')) || (theByte == '-'))
			{
				theToken = HandleNumeric(theByte);
			}
			else if (theByte == '.')
			{
				theToken = HandleDecimal();
			}
			else if (theByte <= ' ')
			{
				break;
			}
			else
			{
				theToken = HandleSymbol(theByte);
			}
		}
		if (theToken != NULL)
		{
			return theToken;
		}
	}
}
Beispiel #3
0
enum Boolean AnalyzeText(char *tempInputCommand)
{
		enum Boolean labelFound=FALSE,firstField=TRUE,handleLineDone=FALSE;
		char *directive=NULL;
		enum ItemType type;
		char *tempItem=NULL;
		char *label=NULL,*command=NULL,*operands=NULL;
		int loc=0;
		enum Directive currentDirective;
		int *curLoc,stringLength;


		curLoc=&loc;

		stringLength=strlen(tempInputCommand);
		if(strlen(tempInputCommand)==0 || strcmp(tempInputCommand,"")==0)
				return FALSE;
		if(tempInputCommand[0]==';')
			return FALSE;
		while((*curLoc)<stringLength && handleLineDone==FALSE)
		{
			tempItem=ReadWord(tempInputCommand,curLoc,' ');

			tempItem=StringTrim(tempItem);
			if(tempItem[strlen(tempItem)-1]==':')
			{
					type=TLabel;
					labelFound=TRUE;
			}
			else if(tempItem[0]=='.')
					type=TDirective;
			else
				type=TCommand;

			switch(type)
			{
			case TDirective:
				/*directive*/

				ALLOCATE_STRING(directive,strlen(tempItem));
				strcpy(directive,tempItem);

				/* Create BMC  */
				CreateBmc(tempInputCommand+(*curLoc),directive,type,label,command,operands);
				handleLineDone=TRUE;
				currentDirective=WhatDirective(directive);

				if(currentDirective!=EXTERN && currentDirective !=ENTRY)
					HandleDirective(tempInputCommand,label,directive);	
				else
				{
					operands=ReadWord(tempInputCommand,curLoc,' ');
					operands=StringTrim(operands);
					FIX_NULL_STRING(operands);
					AddLinkageItem(&Linkage_List,currentDirective,operands,"?");
				}

					break;
			case TCommand:
				AnalyzeCommand(tempInputCommand);
				handleLineDone=TRUE;
					break;
			case TLabel:
				label=(char*)malloc(sizeof(char));
				label=HandleLabel(tempItem,tempInputCommand,curLoc);
					break;
				default: /* cosmetics only*/
					break;
			}
			firstField=FALSE;

		}
return TRUE;
}