private void ProcessNextCodeStatement(bool allowVariableDeclarations)
{
Token nextToken = _source.PeekNextToken();
while (nextToken is ModifierToken)
{
_source.ReadNextToken();
_state.NextTokenModifiers.Add((ModifierToken)nextToken);
nextToken = _source.PeekNextToken();
}
if (nextToken is EndOfStreamToken)
{
throw new CompilerMessage(ErrorCode.EndOfInputReached, "The end of the script was reached in the middle of a function");
}
if ((nextToken is KeywordToken) &&
(((KeywordToken)nextToken).SymbolType == PredefinedSymbol.OpenBrace))
{
ProcessCodeBlock();
}
else if (nextToken is KeywordToken)
{
_source.ReadNextToken();
ProcessKeyword((KeywordToken)nextToken);
}
else if (nextToken.IsVariableType)
{
_source.PushLocation();
Token variableType = _source.ReadNextToken();
if (_source.NextIsKeyword(PredefinedSymbol.Dot))
{
// it's a static member access
_source.PopLocation();
GenerateCodeForExpression(ReadExpression(true, PredefinedSymbol.Semicolon));
}
else
{
_source.DeletePushedLocation();
if (!allowVariableDeclarations)
{
throw new CompilerMessage(ErrorCode.VariableDeclarationNotAllowedHere, "The variable would go out of scope as soon as it was declared");
}
do
{
DeclareLocalVariable(variableType);
}
while (_source.NextIsKeyword(PredefinedSymbol.Comma));
_source.ExpectKeyword(PredefinedSymbol.Semicolon);
_state.NextTokenModifiers.Clear();
}
}
else
{
GenerateCodeForExpression(ReadExpression(true, PredefinedSymbol.Semicolon));
}
}