コード例 #1
0
ファイル: syntax.cpp プロジェクト: ajithperera/acesiii
/*====================================
The function functionsyntax anylyzes the token array stored in outArray.
variable lexpos keeps tracking the position of the outArray.
string temp is the char array of lexical meanings.
====================================*/
void functionsyntax(int &lexpos, int& lineno)
{
    int sialnameno=0;
    if (outArray[lexpos]!=sial)
        outerror(lineno, "Data type is missing.");
    else
    {
        if(!lexmovenext(lexpos)) return;
    }

    if (id!=outArray[lexpos])               //id
        outerror(lineno, "<---Identifier missing.");
    else
    {
        sialnameno=idnosyn++;
        if(!lexmovenext(lexpos)) return;
    }
    moveoverreturn(lexpos, lineno);


    while (IsDeclaration (lexpos) && !endofoutArray)        //declaration
    {
        declarationsyntax(lexpos, lineno);
    }

    while (IsProc (lexpos)&& !endofoutArray)                //proc
    {
        procsyntax(lexpos, lineno);
    }

    Instruct.insert(start, 0);

    while(!endofoutArray &&endsial!=outArray[lexpos])
    {
        while(IsInstruction (lexpos) && !endofoutArray )    //instruction
        {
            instructionsyntax(lexpos, lineno);
        }
        if (!endofoutArray&&endsial!=outArray[lexpos])
            moveoverreturn(lexpos, lineno);
    }

    if (endsial!=outArray[lexpos])                         //endsial
    {
        outerror(lineno, "not instructions. endsial is missing.");
        return;
    }
    else
        lexmovenext(lexpos);

    if (idname[sialnameno]!=idname[idnosyn])
    {
        outerror(lineno, "endsial name does not match.");
    }
    else
    {
        idnosyn++;
        lexmovenext(lexpos);
    }
}
コード例 #2
0
asCScriptNode *asCParser::ParseFor()
{
	asCScriptNode *node = new asCScriptNode(snFor);

	sToken t;
	GetToken(&t);
	if( t.type != ttFor )
	{
		Error(ExpectedToken("for"), &t);
		return node;
	}

	node->UpdateSourcePos(t.pos, t.length);

	GetToken(&t);
	if( t.type != ttOpenParanthesis )
	{
		Error(ExpectedToken("("), &t);
		return node;
	}

	if( IsDeclaration() )
		node->AddChildLast(ParseDeclaration());
	else
		node->AddChildLast(ParseExpressionStatement());
	if( isSyntaxError ) return node;

	node->AddChildLast(ParseExpressionStatement());
	if( isSyntaxError ) return node;

	GetToken(&t);
	if( t.type != ttCloseParanthesis )
	{
		RewindTo(&t);

		node->AddChildLast(ParseAssignment());
		if( isSyntaxError ) return node;

		GetToken(&t);
		if( t.type != ttCloseParanthesis )
		{
			Error(ExpectedToken(")"), &t);
			return node;
		}
	}

	node->AddChildLast(ParseStatement());
	
	return node;
}
コード例 #3
0
asCScriptNode *asCParser::ParseStatementBlock()
{
	asCScriptNode *node = new asCScriptNode(snStatementBlock);

	sToken t1;

	GetToken(&t1);
	if( t1.type != ttStartStatementBlock )
	{
		Error(ExpectedToken("{"), &t1);
		return node;
	}

	node->UpdateSourcePos(t1.pos, t1.length);

	for(;;)
	{
		while( !isSyntaxError )
		{
			GetToken(&t1);
			if( t1.type == ttEndStatementBlock )
			{
				node->UpdateSourcePos(t1.pos, t1.length);

				// Statement block is finished
				return node;
			}
			else
			{
				RewindTo(&t1);

				if( IsDeclaration() )
					node->AddChildLast(ParseDeclaration());
				else
					node->AddChildLast(ParseStatement());
			}
		}

		if( isSyntaxError )
		{
			// Search for either ';', '{', '}', or end
			GetToken(&t1);
			while( t1.type != ttEndStatement && t1.type != ttEnd &&
				   t1.type != ttStartStatementBlock && t1.type != ttEndStatementBlock )
			{
				GetToken(&t1);
			}

			// Skip this statement block
			if( t1.type == ttStartStatementBlock )
			{
				// Find the end of the block and skip nested blocks
				int level = 1;
				while( level > 0 )
				{
					GetToken(&t1);
					if( t1.type == ttStartStatementBlock ) level++;
					if( t1.type == ttEndStatementBlock ) level--;
					if( t1.type == ttEnd ) break;
				}
			}
			else if( t1.type == ttEndStatementBlock )
			{
				RewindTo(&t1);
			}
			else if( t1.type == ttEnd )
			{
				Error(TXT_UNEXPECTED_END_OF_FILE, &t1);
				return node;
			}

			isSyntaxError = false;
		}
	}
	return 0;
}