コード例 #1
0
        private void ProcessEnumDeclaration()
        {
            Token      enumName       = _source.ReadNextTokenAndThrowIfAlreadyDefined();
            ScriptEnum enumDefinition = new ScriptEnum(enumName.Name);

            enumName.Define(TokenType.EnumType, enumDefinition);
            enumName.IsVariableType = true;

            _source.ExpectKeyword(PredefinedSymbol.OpenBrace);
            int nextEnumValue = 0;

            while (!_source.NextIsKeyword(PredefinedSymbol.CloseBrace))
            {
                Token        enumEntry = _source.ReadNextTokenAndThrowIfAlreadyDefined();
                KeywordToken nextToken = _source.ReadNextAsKeyword();
                if (nextToken.SymbolType == PredefinedSymbol.SetEqual)
                {
                    nextEnumValue = _source.ReadNextAsConstInt();
                    nextToken     = _source.ReadNextAsKeyword();
                }

                enumDefinition.Values.Add(enumEntry.Name, nextEnumValue);
                enumEntry.Define(TokenType.Constant, nextEnumValue);
                nextEnumValue++;

                if (nextToken.SymbolType == PredefinedSymbol.CloseBrace)
                {
                    break;
                }
                else if (nextToken.SymbolType != PredefinedSymbol.Comma)
                {
                    throw new CompilerMessage(ErrorCode.UnexpectedToken, "Expected comma at '" + nextToken.Name + "'");
                }
            }

            _source.ExpectKeyword(PredefinedSymbol.Semicolon);
        }
コード例 #2
0
ファイル: ScriptCompiler.cs プロジェクト: Aquilon96/ags
		private void ProcessEnumDeclaration()
		{
			Token enumName = _source.ReadNextTokenAndThrowIfAlreadyDefined();
			ScriptEnum enumDefinition = new ScriptEnum(enumName.Name);
			enumName.Define(TokenType.EnumType, enumDefinition);
			enumName.IsVariableType = true;

			_source.ExpectKeyword(PredefinedSymbol.OpenBrace);
			int nextEnumValue = 0;

			while (!_source.NextIsKeyword(PredefinedSymbol.CloseBrace))
			{
				Token enumEntry = _source.ReadNextTokenAndThrowIfAlreadyDefined();
				KeywordToken nextToken = _source.ReadNextAsKeyword();
				if (nextToken.SymbolType == PredefinedSymbol.SetEqual)
				{
                    nextEnumValue = _source.ReadNextAsConstInt();
					nextToken = _source.ReadNextAsKeyword();
				}

				enumDefinition.Values.Add(enumEntry.Name, nextEnumValue);
				enumEntry.Define(TokenType.Constant, nextEnumValue);
				nextEnumValue++;

				if (nextToken.SymbolType == PredefinedSymbol.CloseBrace)
				{
					break;
				}
				else if (nextToken.SymbolType != PredefinedSymbol.Comma)
				{
					throw new CompilerMessage(ErrorCode.UnexpectedToken, "Expected comma at '" + nextToken.Name + "'");
				}
			}

			_source.ExpectKeyword(PredefinedSymbol.Semicolon);
		}