Пример #1
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     Init.OnAnalyzerVisit(analyzer, block);
     Test.OnAnalyzerVisit(analyzer, block);
     Update.OnAnalyzerVisit(analyzer, block);
     Block.OnAnalyzerVisit(analyzer, block);
 }
Пример #2
0
        public override ReturnType CalcReturnType(SemanticAnalyzer analyzer)
        {
            //Dictionary<ReturnType, int> cast = new Dictionary<ReturnType, int>()
            //{
            //    {ReturnType.Char, 1},
            //    {ReturnType.Int, 2},
            //    {ReturnType.Float, 3},
            //};
            //int left, right;
            //try
            //{
            //    cast.TryGetValue(Left.CalcReturnType(analyzer), out left);
            //    cast.TryGetValue(Right.CalcReturnType(analyzer), out right);
            //}
            //catch
            //{
            //    throw new SemanticError($"Invalid Operand Type {Left}({Left.CalcReturnType(analyzer)}) and {Right}({Right.CalcReturnType(analyzer)})");
            //}
            ReturnType leftRet  = Left.CalcReturnType(analyzer);
            ReturnType rightRet = Right.CalcReturnType(analyzer);

            if (leftRet != rightRet)
            {
                throw new SemanticError($"Invalid Operand {leftRet} {Operator} {rightRet}");
            }
            return(leftRet);
        }
Пример #3
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     foreach (VariableDeclarator declarator in Declarators)
     {
         declarator.OnAnalyzerVisit(analyzer, block);
     }
 }
Пример #4
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     analyzer.AddBlock(this.BlockId, block);
     foreach (Statement statement in Statements)
     {
         statement.OnAnalyzerVisit(analyzer, BlockId);
     }
 }
Пример #5
0
        public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
        {
            SemanticAnalyzer tanalyzer = analyzer;

            foreach (Statement statement in Statements)
            {
                statement.OnAnalyzerVisit(tanalyzer, 0);
            }
        }
Пример #6
0
 // This is VISITED only within Expression as an variable
 // In FunctionDecl and VariableDecl it is added to SymbolTable
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     BlockId = block;
     if (true)
     {
         symbol = analyzer.FindVariable(BlockId, IdentifierName);
         Return = (ReturnType)((VariableSymbol)symbol).VariableType;
     }
 }
Пример #7
0
        public override ReturnType CalcReturnType(SemanticAnalyzer analyzer)
        {
            ReturnType var = Identifier.CalcReturnType(analyzer);
            ReturnType exp = Value.CalcReturnType(analyzer);

            if (var != exp)
            {
                throw new SemanticError($"Invalid Assignment {var} = {exp}");
            }
            return(var);
        }
Пример #8
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     symbol = new FunctionSymbol(block, Identifier.IdentifierName, ReturnType, ArgumentList);
     analyzer.AddSymbol(symbol);
     foreach (FormalArgument arg in ArgumentList)
     {
         VariableSymbol symbol = new VariableSymbol(Block.BlockId, arg.VariableType, arg.Identifier.IdentifierName);
         arg.Identifier.symbol = symbol;
         analyzer.AddSymbol(symbol);
     }
     Block.OnAnalyzerVisit(analyzer, block);
 }
Пример #9
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     foreach (Expression arg in Arguments)
     {
         arg.OnAnalyzerVisit(analyzer, block);
     }
     Symbol = analyzer.FindFunction(Identifier.IdentifierName, Arguments);
     if (Symbol == null)
     {
         throw new SemanticError($"No corresponding function defined as {this.Identifier.IdentifierName}");
     }
     Return = Symbol.ReturnType;
 }
Пример #10
0
        public override ReturnType CalcReturnType(SemanticAnalyzer analyzer)
        {
            ReturnType r = new Dictionary <SyntaxNodeType, ReturnType>()
            {
                { SyntaxNodeType.StringLiteral, ReturnType.Void },
                { SyntaxNodeType.CharLiteral, ReturnType.Char },
                { SyntaxNodeType.IntegerLiteral, ReturnType.Int },
                { SyntaxNodeType.FloatLiteral, ReturnType.Float },
                { SyntaxNodeType.BooleanLiteral, ReturnType.Char },
            }[this.Type];

            Return = r;
            return(r);
        }
Пример #11
0
 public override ReturnType CalcReturnType(SemanticAnalyzer analyzer)
 {
     return(this.Expression.CalcReturnType(analyzer));
 }
Пример #12
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     Expression.OnAnalyzerVisit(analyzer, block);
     Return = Expression.CalcReturnType(analyzer);
 }
Пример #13
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     // 没有 Statement 类的节点
     throw new NotImplementedException();
 }
Пример #14
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     Left.OnAnalyzerVisit(analyzer, block);
     Right.OnAnalyzerVisit(analyzer, block);
     Return = CalcReturnType(analyzer);
 }
Пример #15
0
 public virtual ReturnType CalcReturnType(SemanticAnalyzer analyzer)
 {
     throw new NotImplementedException();
 }
Пример #16
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     Identifier.OnAnalyzerVisit(analyzer, block);
     Value.OnAnalyzerVisit(analyzer, block);
 }
Пример #17
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     ReturnValue.OnAnalyzerVisit(analyzer, block);
 }
Пример #18
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     // 没有 PrimaryExpression类的节点
     throw new NotImplementedException();
 }
Пример #19
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     symbol = new VariableSymbol(block, DeclareType, Identifier.IdentifierName);
     analyzer.AddSymbol(symbol);
     Identifier.OnAnalyzerVisit(analyzer, block);
 }
Пример #20
0
 public override ReturnType CalcReturnType(SemanticAnalyzer analyzer)
 {
     throw new NotImplementedException();
 }
Пример #21
0
 public override void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     analyzer.AddLiteral(this);
     CalcReturnType(analyzer);
 }
Пример #22
0
 public override ReturnType CalcReturnType(SemanticAnalyzer analyzer)
 {
     return(Return == ReturnType.Void ? (ReturnType)analyzer.FindVariable(BlockId, IdentifierName).VariableType : Return);
 }
Пример #23
0
 public override ReturnType CalcReturnType(SemanticAnalyzer analyzer)
 {
     return(analyzer.FindFunction(Identifier.IdentifierName, Arguments).ReturnType);
 }
Пример #24
0
 public virtual void OnAnalyzerVisit(SemanticAnalyzer analyzer, int block)
 {
     throw new NotImplementedException();
 }