コード例 #1
0
        /// <summary>
        /// Carries out identification on a const declaration node
        /// </summary>
        /// <param name="constDeclaration">The node to perform identification on</param>
        private void PerformIdentificationOnConstDeclaration(ConstDeclarationNode constDeclaration)
        {
            Token token   = constDeclaration.Identifier.IdentifierToken;
            bool  success = SymbolTable.Enter(token.Spelling, constDeclaration);

            PerformIdentification(constDeclaration.Expression);
        }
コード例 #2
0
        /// <summary>
        /// Carries out identification on a const declaration node
        /// </summary>
        /// <param name="constDeclaration">The node to perform identification on</param>
        private void PerformIdentificationOnConstDeclaration(ConstDeclarationNode constDeclaration)
        {
            Token token   = constDeclaration.Identifier.IdentifierToken;
            bool  success = SymbolTable.Enter(token.Spelling, constDeclaration);

            if (!success)
            {
                Reporter.ReportError($"{token.Position} -> Const declaration with {token.Spelling} " +
                                     $"already exists in the current scope");
            }
            PerformIdentification(constDeclaration.Expression);
        }
コード例 #3
0
        /// <summary>
        /// Carries out identification on a const declaration node
        /// </summary>
        /// <param name="constDeclaration">The node to perform identification on</param>
        private void PerformIdentificationOnConstDeclaration(ConstDeclarationNode constDeclaration)
        {
            Token token   = constDeclaration.Identifier.IdentifierToken;
            bool  success = SymbolTable.Enter(token.Spelling, constDeclaration);

            if (success)
            {
                PerformIdentification(constDeclaration.Expression);
            }
            else
            {
                IsItDirty();
                Reporter.IdentifierErrorPositions.Add($"Error has occured here: {token.Position}, const already declared");
            }
        }
コード例 #4
0
 /// <summary>
 /// Generates code for a const declaration node
 /// </summary>
 /// <param name="constDeclaration">The node to generate code for</param>
 private void GenerateCodeForConstDeclaration(ConstDeclarationNode constDeclaration)
 {
     Debugger.Write("Generating code for Const Declaration");
     if (constDeclaration.Expression is CharacterExpressionNode charLiteral)
     {
         constDeclaration.RuntimeEntity = new RuntimeKnownConstant((short)charLiteral.CharLit.Value);
     }
     else if (constDeclaration.Expression is IntegerExpressionNode intLiteral)
     {
         constDeclaration.RuntimeEntity = new RuntimeKnownConstant((short)intLiteral.IntLit.Value);
     }
     else
     {
         GenerateCodeFor(constDeclaration.Expression);
         byte  constantSize     = constDeclaration.EntityType.Size;
         short currentScopeSize = scopes.GetLocalScopeSize();
         constDeclaration.RuntimeEntity = new RuntimeUnknownConstant(currentScopeSize, constantSize);
         scopes.AddToLocalScope(constantSize);
     }
 }
コード例 #5
0
ファイル: CodeGenerator.cs プロジェクト: smack0007/Snowflake
        private static void GenerateConstDeclaration(ConstDeclarationNode node, DataContext data)
        {
            data.VariableMap.DeclareVariable(node.ConstName, node.Line, node.Column);

            StartLine(data, "context.DeclareVariable(\"{0}\", isConst: true, value: ", node.ConstName);

            GenerateExpression(node.ValueExpression, data);

            EndLine(data, ");");
        }