예제 #1
0
        // 构造函数
        public MainPage()
        {
            InitializeComponent();


            string bmobId = "2bf438a29c5411c813e6e50a1aedfd0c";

            JYCaoZuo.getCaoZuo().page = this;
            JYCaoZuo.getCaoZuo().init(bmobId);


            // 用于本地化 ApplicationBar 的示例代码
            //BuildLocalizedApplicationBar();
            string daiMa = "int i = 0;while(i<100){ i = i+1;write(i);}";

            //使用方法
            //1语义分析
            LexicalAnalysis la = new LexicalAnalysis();

            string        outStr  = la.Analyze(daiMa);
            List <object> errList = la.errlist;

            Debug.WriteLine(outStr);


            Analysis ciFaFenXi = new Analysis();

            //判断语义是否有误
            if (ciFaFenXi.syntaxAalysis(la))
            {
            }
            else
            {
                Debug.WriteLine(ciFaFenXi.errInfo.ToString());
            }
            //2 执行算法
            MidCode m0 = new MidCode(ciFaFenXi);

            m0.Scan();
            Interpret runner = new Interpret();

            runner.GetRun(m0.c);
            //得到结果
            string jieGuo = runner.jieGuo;

            Debug.WriteLine(jieGuo);

            m0.clear();
        }
예제 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //执行结果
            //使用方法
            //1语义分析

            string daiMa = txtForDaiMa.Text;

            JYCaoZuo.getCaoZuo().addaoZuo("点击了执行代码:" + daiMa);
            LexicalAnalysis la = new LexicalAnalysis();

            string        outStr  = la.Analyze(daiMa);
            List <object> errList = la.errlist;

            Debug.WriteLine(outStr);


            Analysis ciFaFenXi = new Analysis();

            //判断语义是否有误
            if (ciFaFenXi.syntaxAalysis(la))
            {
            }
            else
            {
                txtForJieGuo.Text = ciFaFenXi.errInfo.ToString() + "\n" + outStr;
                Debug.WriteLine(ciFaFenXi.errInfo.ToString());
                return;
            }
            //2 执行算法
            MidCode m0 = new MidCode(ciFaFenXi);

            m0.Scan();
            Interpret runner = new Interpret();

            runner.GetRun(m0.c);
            //得到结果
            string jieGuo = runner.jieGuo;

            Debug.WriteLine(jieGuo);
            txtForJieGuo.Text = jieGuo + "\n" + outStr;

            m0.clear();
            JYCaoZuo.getCaoZuo().addaoZuo("点击了执行代码:" + daiMa + ",结果:" + txtForJieGuo.Text);
        }