Example #1
0
        private async void Syntactic_Click(object sender, RoutedEventArgs e)
        {
            Progress.Visibility = Visibility.Visible;
            var result = await Task.Run(() => {
                return(SyntaxParser());
            });

            Progress.Visibility = Visibility.Collapsed;
            if (result == true)
            {
                ModernDialog modernDialog = new ModernDialog
                {
                    Title   = "LR(1)分析表建立成功!",
                    Content = "查看结果?"
                };
                modernDialog.Buttons = new Button[] { modernDialog.OkButton, modernDialog.CancelButton };
                modernDialog.ShowDialog();
                result = modernDialog.MessageBoxResult.ToString();
                if (result == "OK")
                {
                    LR1 page = new LR1();
                    page.Show();
                }
                else
                {
                    Semantic.IsEnabled = true;
                }
            }
        }
Example #2
0
        private void BuildLR1Sets()
        {
            Debug.Assert(Grammar.Accept != null);
            Debug.Assert(Grammar.Eof != null);

            var start    = new LR1(CoreFactory.Get(Grammar.Accept.Productions[0]), true, Grammar.Eof.First);
            var startSet = new LR1Set(start);

            var closer = new LR1Set.Closer2(Grammar.LR1Sets, startSet);

            closer.Go();
        }
        private void OpenFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileName = new OpenFileDialog();

            fileName.InitialDirectory = Application.StartupPath;
            fileName.Filter           = "txt files (*.txt)|*.txt";
            fileName.FilterIndex      = 1;
            fileName.RestoreDirectory = true;
            if (fileName.ShowDialog() == DialogResult.OK)
            {
                //MessageBox.Show("OK");
                string path = fileName.FileName.ToString();
                backEnd = new LR1(path);
                Dictionary <string, List <string> > rule = backEnd.GetRuleSet();
                RuleDisplay.Clear();
                if (rule == null)
                {
                    MessageBox.Show("LR1运行失败,输入的规则式有问题");
                }
                else
                {
                    foreach (string key in rule.Keys)
                    {
                        foreach (string showRule in rule[key])
                        {
                            RuleDisplay.AppendText(key + "->" + showRule + "\r\n");
                        }
                    }
                    backEnd.SolveFirstSet();
                    backEnd.SolveFollowSet();
                    backEnd.BuildLR1ForView();
                    isSyntaxValid = backEnd.BuildTable();
                    MessageBox.Show("输入的规则式合法");
                    GetLR0.Enabled = true;
                }
            }
        }
Example #4
0
    public void DrawChart_Performance(string NET_CHANGE_NORMALIZED1, string NET_CHANGE_NORMALIZED2, string Y_AXIS_LABELS_NET_CHANGE, string X_AXIS_LABEL, string X_AXIS_LABEL_POS)
    {
        if (gameObject.activeSelf == false)
        {
            gameObject.SetActive(true);
        }

        if (LineMask.GetComponent <Animation>().isPlaying)
        {
            LineMask.GetComponent <Animation>().Stop();
        }

        //////////////////////////////////////////////////////////////////////////////
        //Performance Chart Specific
        //////////////////////////////////////////////////////////////////////////////

        ClearGraph();

        LineRenderer LR1;
        LineRenderer LR2;

        Line_Perf1.SetActive(true);
        Line_Perf2.SetActive(true);
        Graph_DotPerf1.SetActive(true);
        Graph_DotPerf2.SetActive(true);

        PaddingTop   = 0.0f;
        PaddingSides = 0.0f;

        //////////////////////////////////////////////////////////////////////////////
        //Setup the Graph
        //////////////////////////////////////////////////////////////////////////////

        SetupGraph(PaddingTop, PaddingSides);

        //////////////////////////////////////////////////////////////////////////////
        //Drawing the Two lines
        //////////////////////////////////////////////////////////////////////////////

        string[] graphPoints_1 = NET_CHANGE_NORMALIZED1.Split(';');
        string[] graphPoints_2 = NET_CHANGE_NORMALIZED2.Split(';');
        float    pxSpacing_1   = 1000.0f / graphPoints_1.Length;
        float    pxSpacing_2   = 1000.0f / graphPoints_2.Length;

        LR1 = Line_Perf1.GetComponent <LineRenderer>();
        LR2 = Line_Perf2.GetComponent <LineRenderer>();

        int posCount_1 = 0;
        int posCount_2 = 0;

        var positions_1 = new List <Vector3>();
        var positions_2 = new List <Vector3>();

        if (graphPoints_1.Length > 1 && graphPoints_2.Length > 1)
        {
            //Line 1
            for (int i = 0; i < graphPoints_1.Length; i++)
            {
                if (graphPoints_1[i] != "")
                {
                    posCount_1++;
                    try
                    {
                        positions_1.Add(new Vector3((((pxSpacing_1) + (pxSpacing_1 / (graphPoints_1.Length - 1))) * i) * xScale, float.Parse(graphPoints_1[i]) * yScale, 0.0f));
                        Graph_DotPerf1.transform.localPosition = new Vector3((((pxSpacing_1) + (pxSpacing_1 / (graphPoints_1.Length - 1))) * i) * xScale, float.Parse(graphPoints_1[i]) * yScale, -0.05f);
                    }

                    catch
                    {
                        Debug.LogError("graph 1 point = " + graphPoints_1[i]);
                    }
                }
            }

            //Line 2
            for (int i = 0; i < graphPoints_2.Length; i++)
            {
                if (graphPoints_2[i] != "")
                {
                    posCount_2++;
                    try
                    {
                        positions_2.Add(new Vector3((((pxSpacing_2) + (pxSpacing_2 / (graphPoints_2.Length - 1))) * i) * xScale, float.Parse(graphPoints_2[i]) * yScale, 0.0f));
                        Graph_DotPerf2.transform.localPosition = new Vector3((((pxSpacing_2) + (pxSpacing_2 / (graphPoints_2.Length - 1))) * i) * xScale, float.Parse(graphPoints_2[i]) * yScale, -0.05f);
                    }

                    catch
                    {
                        Debug.LogError("graph 2 point = " + graphPoints_2[i]);
                    }
                }
            }
        }
        else
        {
            ClearGraph();
        }

        if (posCount_1 > 0 || posCount_2 > 0)
        {
            LR1.positionCount = posCount_1;
            LR1.SetPositions(positions_1.ToArray());
            LR1.Simplify(0.15f);

            LR2.positionCount = posCount_2;
            LR2.SetPositions(positions_2.ToArray());
            LR2.Simplify(0.15f);
        }
        else
        {
            ClearGraph();
        }

        //////////////////////////////////////////////////////////////////////////////
        //Displaying the Y-Axis
        //////////////////////////////////////////////////////////////////////////////

        foreach (Transform child in transform.GetComponentsInChildren <Transform>())
        {
            if (child.gameObject.tag == "Graph_LabelY")
            {
                Destroy(child.gameObject);
            }
        }

        string[] yLabels   = Y_AXIS_LABELS_NET_CHANGE.Split(';');
        float    pySpacing = 1000.0f / yLabels.Length;

        for (int i = 0; i < yLabels.Length; i++)
        {
            GameObject instaY = Instantiate(Y_Label, this.GetComponent <Transform>());
            instaY.transform.localPosition = new Vector3((((instaY.GetComponent <RectTransform>().rect.width / 2.0f) * -1.0f) * 0.1f) - yLabelOffset - (PaddingSides * xScale), (((pySpacing) + (pySpacing / (yLabels.Length - 1))) * i) * yScale, -0.01f);
            instaY.GetComponent <TextMeshPro>().SetText(yLabels[i] + "%");

            Transform GridY = instaY.transform.GetChild(0);
            GridY.localPosition = new Vector3((instaY.GetComponent <RectTransform>().rect.width / 2.0f) + (yLabelOffset * 10.0f), 0.0f);
            GridY.localScale    = new Vector3((1000.0f + (PaddingSides * 2.0f)) * xScale * 10.0f, 0.2f, 1.0f);
            GridY.transform.GetChild(0).GetComponent <MeshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 0.35f);
        }

        //////////////////////////////////////////////////////////////////////////////
        //Displaying the X-Axis
        //////////////////////////////////////////////////////////////////////////////

        foreach (Transform child in transform.GetComponentsInChildren <Transform>())
        {
            if (child.gameObject.tag == "Graph_LabelX")
            {
                Destroy(child.gameObject);
            }
        }

        string[] xLabels    = X_AXIS_LABEL.Split(';');
        string[] xLabelsPos = X_AXIS_LABEL_POS.Split(';');

        for (int i = 0; i < xLabelsPos.Length; i++)
        {
            if (xLabelsPos[i] == "")
            {
                xLabelsPos[i] = "0";
            }

            GameObject instaX = Instantiate(X_Label, this.GetComponent <Transform>());
            instaX.transform.localPosition = new Vector3(float.Parse(xLabelsPos[i]) * xScale, 0.0f - xLabelOffset, -0.01f);
            instaX.GetComponent <TextMeshPro>().SetText(xLabels[i]);

            Transform GridX = instaX.transform.GetChild(0);
            GridX.transform.localPosition = new Vector3(0.0f, xLabelOffset * 10.0f);
            GridX.transform.localScale    = new Vector3(0.2f, (1000.0f + PaddingTop) * yScale * 10.0f, 1.0f);
            GridX.transform.GetChild(0).GetComponent <MeshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 0.35f);

            //if (float.Parse(xLabelsPos[i]) < 25.0f)
            //{
            //    instaX.GetComponent<TextMeshPro>().enabled = false;
            //}
        }

        //////////////////////////////////////////////////////////////////////////////
        //Setting up the Line Mask
        //////////////////////////////////////////////////////////////////////////////

        LineMask.transform.localPosition = new Vector3(-PaddingSides * xScale, 0.0f, -0.06f);
        LineMask.transform.localScale    = new Vector3(((1000.0f + (PaddingSides * 2.0f)) * xScale) + 0.1f, (1000.0f + PaddingTop) * yScale, 1.0f);
        LineMask.GetComponent <Animation>().Play();
    }
 public void InputAlorithm(LR1 al)
 {
     alogrithm = al;
 }