Exemple #1
0
        public List <TNode> PreviousX(TNode p_to, string p_from)
        {
            if (p_to is null)
            {
                return(null);
            }

            List <TNodeTypeEnum> acceptableType = DetermineAcceptableTypes(p_from);
            List <TNode>         candidates;

            if (p_from != "_")
            {
                candidates = AstManager.GetInstance().GetNodes(QueryPreProcessor.GetInstance().declarationsList[p_from]);
            }
            else
            {
                candidates = AstManager.GetInstance().GetNodes("_");
            }
            List <TNode> resultList = new List <TNode>();

            if (candidates is null)
            {
                return(null);
            }

            foreach (var c in candidates)
            {
                if (IsNextX((int)c.programLine, (int)p_to.programLine))
                {
                    resultList.Add(c);
                }
            }

            return(resultList.Count > 0 ? resultList : null);
        }
Exemple #2
0
        private void parseQueryButton_Click(object sender, RoutedEventArgs e)
        {
            string query = StringFromRichTextBox(queryRichTextBox);

            try
            {
                query = QueryPreProcessor.GetInstance().Parse(query);

                addLog("PQL Parser: Ok");
            }
            catch (Exception ex)
            {
                addLog("PQL Parser: " + ex.GetType().Name + ": " + ex.Message);
                good = false;
                return;
            }
            finally
            {
                queryRichTextBox.Document.Blocks.Clear();
                queryRichTextBox.Document.Blocks.Add(new Paragraph(new Run(query)));
            }
            good = true;
        }
Exemple #3
0
        private void evaluateQueryButton_Click(object sender, RoutedEventArgs e)
        {
            if (!good)
            {
                return;
            }
            resultRichTextBox.Document.Blocks.Clear();

            try
            {
                try
                {
                    List <QueryProcessingSusbsytem.Condition> conditionsList = QueryPreProcessor.GetInstance().conditionsList;
                    QueryEvaluator.GetInstance().Evaluate(conditionsList);
                }
                catch (NoResultsException ex)
                {
                    addLog("Q Evaluator: " + ex.GetType().Name + ": " + ex.Message);
                    good = false;
                }
                finally
                {
                    //tutaj QueryProjector wkracza do gry - interpretuje instancję klasy Result
                    QueryResult    queryResult    = QueryResult.GetInstance();
                    QueryProjector queryProjector = QueryProjector.GetInstance();

                    resultRichTextBox.Document.Blocks.Add(new Paragraph(new Run(queryProjector.PrintResult())));
                    addLog("Q Evaluator: Result: ok, check Result window");
                }
            }
            catch (Exception ex)
            {
                addLog("FATAL ERROR: " + ex.GetType().Name + ": " + ex);
            }
            good = true;
        }
Exemple #4
0
        private List <TNodeTypeEnum> DetermineAcceptableTypes(string arg)
        {
            List <TNodeTypeEnum> result = new List <TNodeTypeEnum>();
            int tmp;

            if (arg == "_" || Int32.TryParse(arg, out tmp))
            {
                foreach (TNodeTypeEnum v in Enum.GetValues(typeof(TNodeTypeEnum)))
                {
                    result.Add(v);
                }
                return(result);
            }

            string argType = QueryPreProcessor.GetInstance().declarationsList[arg];

            switch (argType)
            {
            case "procedure":
            {
                result.Add(TNodeTypeEnum.Procedure);
            }
            break;

            case "call":
            {
                result.Add(TNodeTypeEnum.Call);
            }
            break;

            case "assign":
            {
                result.Add(TNodeTypeEnum.Assign);
            }
            break;

            case "if":
            {
                result.Add(TNodeTypeEnum.If);
            }
            break;

            case "while":
            {
                result.Add(TNodeTypeEnum.While);
            }
            break;

            case "stmt":
            case "stmtLst":
            case "prog_line":
            {
                result.Add(TNodeTypeEnum.Call);
                result.Add(TNodeTypeEnum.While);
                result.Add(TNodeTypeEnum.If);
                result.Add(TNodeTypeEnum.Assign);
            }
            break;
            }

            return(result);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            string SourceCode = "";
            PkbAPI pkb;

            if (args.Length == 0)
            {
                Console.WriteLine("No parameter with path to file");
                Console.WriteLine("Program exit.");
                return;
            }

            string path = args[0];

            try
            {
                SourceCode = File.ReadAllText(path);
                Console.WriteLine("File ok: " + path);

                SourceCode = ParserByTombs.Instance.Parse(SourceCode);
                Console.WriteLine("Source Parsed ok");

                pkb = ParserByTombs.Instance.pkb;
                QueryEvaluator.GetInstance().pkb = pkb;
                QueryProjector.GetInstance().Pkb = pkb;
                Console.WriteLine("PKB ok");

                AstManager.GetInstance().GenerateStructures(SourceCode, pkb);
                Console.WriteLine("AST ok");

                CfgManager.GetInstance().GenerateStructure(SourceCode, pkb);
                Console.WriteLine("CFG ok");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Before");
                Console.WriteLine(ex.GetType().Name + ": " + ex);
            }
            Console.WriteLine("Ready");

            int i = 0;

            while (true)
            {
                string answer = "";
                string query  = Console.ReadLine();
                query += " " + Console.ReadLine();

                try
                {
                    query = QueryPreProcessor.GetInstance().Parse(query);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("#" + ex.GetType().Name + ": " + ex.Message);
                    continue;
                }

                try
                {
                    List <Condition> conditionsList = QueryPreProcessor.GetInstance().conditionsList;
                    QueryEvaluator.GetInstance().Evaluate(conditionsList);
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    try
                    {
                        QueryResult    queryResult    = QueryResult.GetInstance();
                        QueryProjector queryProjector = QueryProjector.GetInstance();
                        answer = queryProjector.PrintResult();
                    }
                    catch (Exception ex)
                    {
                        answer = "none";
                    }
                }
                Console.WriteLine(answer);
            }

            Console.WriteLine("Program exit.");
            return;
        }