Exemple #1
0
        public override bool SemanticAnalysis()
        {
            try
            {
                IsSemanticCorrect                         = outGraph.SemanticAnalysis();
                outGraph.MainVariable.WasUsed             = true;
                outGraph.MainVariable.WasNewValueUsed     = false;
                outGraph.MainVariable.WasAssignedNewValue = LineNumber;
                if (outGraph.MainVariable.Type != "graph")
                {
                    throw new WrongOperandTypeException(LineNumber, "Floyd", 1, "graph");
                }
            }
            catch (SemanticException e)
            {
                Console.WriteLine(e.Message);
                IsSemanticCorrect = false;
            }

            try
            {
                IsSemanticCorrect                   &= inGraph.SemanticAnalysis();
                inGraph.MainVariable.WasUsed         = true;
                inGraph.MainVariable.WasNewValueUsed = true;
                if (inGraph.MainVariable.Type != "graph" || (inGraph.TypeOfNode != NodeType.Variable))
                {
                    throw new WrongOperandTypeException(LineNumber, "Floyd", 2, "graph");
                }
                if (IsSemanticCorrect)                                                                   //ещё надо сравнить размерности
                {
                    if (int.Parse(inGraph.MainVariable.Value) != int.Parse(outGraph.MainVariable.Value)) //если не равны
                    {
                        throw new UnequalGraphsDimentionsException(LineNumber, outGraph.MainVariable.Name, inGraph.MainVariable.Name);
                    }
                }
            }
            catch (SemanticException e)
            {
                Console.WriteLine(e.Message);
                IsSemanticCorrect = false;
            }
            return(IsSemanticCorrect);
        }
Exemple #2
0
        public override bool SemanticAnalysis()
        {
            try
            {
                IsSemanticCorrect                  = graph.SemanticAnalysis();
                graph.MainVariable.WasUsed         = true;
                graph.MainVariable.WasNewValueUsed = true;
                if (graph.MainVariable.Type != "graph")
                {
                    throw new WrongOperandTypeException(LineNumber, "IsFull", 1, "graph");
                }
            }
            catch (SemanticException e)
            {
                Console.WriteLine(e.Message);
                IsSemanticCorrect = false;
            }

            try
            {
                IsSemanticCorrect &= outVariable.SemanticAnalysis();
                outVariable.MainVariable.WasUsed             = true;
                outVariable.MainVariable.WasNewValueUsed     = false;
                outVariable.MainVariable.WasIdentified       = true;
                outVariable.MainVariable.WasAssignedNewValue = LineNumber;
                if ((outVariable.TypeOfNode != NodeType.Variable) || (outVariable.MainVariable.Type != "bool"))
                {
                    throw new WrongOperandTypeException(LineNumber, "IsFull", 2, "bool variable");
                }
            }
            catch (SemanticException e)
            {
                Console.WriteLine(e.Message);
                IsSemanticCorrect = false;
            }
            //возвращаемся
            return(IsSemanticCorrect);
        }
Exemple #3
0
        public override bool SemanticAnalysis()
        {
            try
            {
                IsSemanticCorrect                  = graph.SemanticAnalysis();
                graph.MainVariable.WasUsed         = true;
                graph.MainVariable.WasNewValueUsed = true;
                if (graph.MainVariable.Type != "graph")
                {
                    throw new WrongOperandTypeException(LineNumber, "GetEdge", 1, "graph");
                }
            }
            catch (SemanticException e)
            {
                Console.WriteLine(e.Message);
                IsSemanticCorrect = false;
            }

            //проверяем первую вершину
            try
            {
                IsSemanticCorrect                 &= first.SemanticAnalysis();
                first.MainVariable.WasUsed         = true;
                first.MainVariable.WasNewValueUsed = true;
                if (first.MainVariable.Type != "int")
                {
                    throw new WrongOperandTypeException(LineNumber, "GetEdge", 2, "int");
                }
                if (!first.MainVariable.WasIdentified)
                {
                    throw new UnidentifiedVariableException(LineNumber, first.MainVariable.Name);
                }
            }
            catch (SemanticException e)
            {
                Console.WriteLine(e.Message);
                IsSemanticCorrect = false;
            }

            //аналогично вторую
            try
            {
                IsSemanticCorrect                  &= second.SemanticAnalysis();
                second.MainVariable.WasUsed         = true;
                second.MainVariable.WasNewValueUsed = true;
                if (second.MainVariable.Type != "int")
                {
                    throw new WrongOperandTypeException(LineNumber, "GetEdge", 3, "int");
                }
                if (!second.MainVariable.WasIdentified)
                {
                    throw new UnidentifiedVariableException(LineNumber, second.MainVariable.Name);
                }
            }
            catch (SemanticException e)
            {
                Console.WriteLine(e.Message);
                IsSemanticCorrect = false;
            }

            //теперь результирующая
            {
                try
                {
                    IsSemanticCorrect               &= Res.SemanticAnalysis();
                    Res.MainVariable.WasUsed         = true;
                    Res.MainVariable.WasNewValueUsed = false;
                    Res.MainVariable.WasIdentified   = true;
                    if (Res.TypeOfNode != NodeType.Variable)
                    {
                        throw new WrongOperandTypeException(LineNumber, "GetEdge", 4, "int variable");
                    }
                }
                catch (SemanticException e)
                {
                    Console.WriteLine(e.Message);
                    IsSemanticCorrect = false;
                }
                //возвращаемся
                return(IsSemanticCorrect);
            }
        }
Exemple #4
0
        public override bool SemanticAnalysis()
        {
            //По сути, создавая граф, мы объявляем новую переменную тип graph
            MainVariable = new Variable();
            numGraph     = ++Counters.graphs;
            MainVariable.AlternativeName = "graph_" + (numGraph).ToString();
            MainVariable.IsDeclared      = true;
            MainVariable.WasIdentified   = true; //переменная объявлена и идентифицирована
            MainVariable.WasNewValueUsed = false;
            MainVariable.WasUsed         = false;
            MainVariable.Name            = graph.Value;
            MainVariable.DeclaredLine    = LineNumber;
            MainVariable.Type            = "graph";
            try
            {
                Variable possibleVariable = parentBlock.BlockVariables.FirstOrDefault(var => var.Name == MainVariable.Name);
                if (possibleVariable != null)
                {
                    IsSemanticCorrect     = false;
                    possibleVariable.Type = "graph"; //меняем тип
                    throw new RedeclaringVariableException(LineNumber, MainVariable.Name);
                }
                parentBlock.BlockVariables.Add(MainVariable); //помещаем в список переменных данного блока
                IsSemanticCorrect = true;
                graph.SemanticAnalysis();
            }
            catch (SemanticException e)
            {
                Console.WriteLine(e.Message);
                IsSemanticCorrect = false; //плохо
            }

            try
            {
                IsSemanticCorrect &= InputVar.SemanticAnalysis();
            }
            catch (SemanticException e)
            {
                Console.WriteLine(e.Message);
                IsSemanticCorrect = false;
            }

            if (InputVar.MainVariable.Type != "graph")
            {
                try
                {
                    string num = InputVar.CanCreateGraph();
                    if (num == "")
                    {
                        IsSemanticCorrect = false;
                        throw new RequredConstantExceptoion(LineNumber);
                    }
                    else
                    {
                        NumVertecies = int.Parse(num);
                        if (NumVertecies <= 0)
                        {
                            throw new PositiveIntegerIsRequiredException(LineNumber);
                        }
                        MainVariable.Value = num;
                    }
                }
                catch (SemanticException e)
                {
                    Console.WriteLine(e.Message);
                    IsSemanticCorrect = false;
                }
                catch (DividingByZeroWarning w)
                {
                    Console.WriteLine(w.Message);
                    IsSemanticCorrect = false;
                }
            }
            return(IsSemanticCorrect);
        }