예제 #1
0
asCScriptNode *asCParser::ParseGlobalVar()
{
	asCScriptNode *node = new asCScriptNode(snGlobalVar);

	// Parse data type
	node->AddChildLast(ParseType(true));
	if( isSyntaxError ) return node;

	sToken t;

	for(;;)
	{
		// Parse identifier
		node->AddChildLast(ParseIdentifier());
		if( isSyntaxError ) return node;

		// If next token is assignment, parse expression
		GetToken(&t);
		if( t.type == ttAssignment )
		{
			GetToken(&t);
			RewindTo(&t);
			if( t.type == ttStartStatementBlock )
			{
				node->AddChildLast(ParseInitList());
				if( isSyntaxError ) return node;
			}
			else
			{
				node->AddChildLast(ParseAssignment());
				if( isSyntaxError ) return node;
			}
		}
		else if( t.type == ttOpenParanthesis ) 
		{
			RewindTo(&t);
			node->AddChildLast(ParseArgList());
			if( isSyntaxError ) return node;
		}
		else
			RewindTo(&t);

		// continue if list separator, else terminate with end statement
		GetToken(&t);
		if( t.type == ttListSeparator )
			continue;
		else if( t.type == ttEndStatement )
		{
			node->UpdateSourcePos(t.pos, t.length);

			return node;
		}
		else
		{
			Error(ExpectedTokens(",", ";").AddressOf(), &t);
			return node;
		}
	}
	return 0;
}
예제 #2
0
void ParseDecl()
{
  if(Token==TOK_INLINE || Token==TOK_FINLINE)
  {
    Match();
    Out(" ");
  }
  ParseType();
/*
  if(Token==TOK_SCOPE)    // must be constrcutor...
  {
    Match();
    if(Token==TOK_NEG)
      Match();
    Match(TOK_TYPE);
  }
  else*/
  {
    Out(" ");
    ParseVarDecl();
  }
    
  if(Token==TOK_OPEN)
  {
    Match(TOK_OPEN);
    ParseParamList();
    Match(TOK_CLOSE);
    if(Token==TOK_CONST)
    {
      Match();
      Out(" ");
    }
    if(Token==TOK_BOPEN)
    {
      //ParseBlock();
      ParseCondBlock();
      NewLine();
    }
    else if(Token==TOK_ASSIGN)
    {
      Match(TOK_ASSIGN);
      Match(TOK_VALUE);
    }
    else if(Token==TOK_COLON)
    {
      Match();
      ParseInitList();
    }
    else
    {          
      Match(TOK_SEMI);
    }
  }
  else
  {
    while(Token==TOK_COMMA)
    {
      Match(TOK_COMMA);
      ParseVarDecl();
    }
    Match(TOK_SEMI);
  }
}
예제 #3
0
asCScriptNode *asCParser::ParseInitList()
{
	asCScriptNode *node = new asCScriptNode(snInitList);

	sToken t1;

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

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

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

		// Statement block is finished
		return node;
	}
	else
	{
		RewindTo(&t1);
		for(;;)
		{
			GetToken(&t1);
			if( t1.type == ttListSeparator )
			{
				// No expression 
				node->AddChildLast(new asCScriptNode(snUndefined));

				GetToken(&t1);
				if( t1.type == ttEndStatementBlock )
				{
					// No expression
					node->AddChildLast(new asCScriptNode(snUndefined));
					node->UpdateSourcePos(t1.pos, t1.length);
					return node;
				}
				RewindTo(&t1);
			}
			else if( t1.type == ttEndStatementBlock )
			{
				// No expression 
				node->AddChildLast(new asCScriptNode(snUndefined));

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

				// Statement block is finished
				return node;
			}
			else if( t1.type == ttStartStatementBlock )
			{
				RewindTo(&t1);
				node->AddChildLast(ParseInitList());
				if( isSyntaxError ) return node;

				GetToken(&t1);
				if( t1.type == ttListSeparator )
					continue;
				else if( t1.type == ttEndStatementBlock )
				{
					node->UpdateSourcePos(t1.pos, t1.length);

					// Statement block is finished
					return node;
				}
				else
				{
					Error(ExpectedTokens("}", ",").AddressOf(), &t1);
					return node;
				}
			}
			else
			{
				RewindTo(&t1);
				node->AddChildLast(ParseAssignment());
				if( isSyntaxError ) return node;


				GetToken(&t1);
				if( t1.type == ttListSeparator )
					continue;
				else if( t1.type == ttEndStatementBlock )
				{
					node->UpdateSourcePos(t1.pos, t1.length);

					// Statement block is finished
					return node;
				}
				else
				{
					Error(ExpectedTokens("}", ",").AddressOf(), &t1);
					return node;
				}
			}
		}
	}
	return 0;
}