Ejemplo n.º 1
0
 public void WriteGv(string path)
 {
     using (var graph = new GvGraphView(path))
     {
         WriteGv(graph);
     }
 }
Ejemplo n.º 2
0
        public void ResolvingAmbiguities()
        {
            using (var interp = new Interpreter<AmbiguousCalculator>())
            {
                interp.Parse("2+8/2");
                Assert.AreEqual(6, interp.Context.Result.Value);

                interp.Parse("8/4/2");
                Assert.AreEqual(1, interp.Context.Result.Value);

                interp.Parse("2+3"); // can be interpreted as a "2 * (+3)"
                Assert.AreEqual(5, interp.Context.Result.Value);

                // Check that implicit multiplication works
                interp.Parse("2 3"); 
                Assert.AreEqual(6, interp.Context.Result.Value);

                // A lot of ambiguities:
                interp.Parse("1+-+6/3"); 
                Assert.AreEqual(-1, interp.Context.Result.Value);
#if false
                using (var g = new GvGraphView("expr.tmp.gv"))
                {
                    interp.BuildTree("1+-+6/3").WriteGraph(g, interp.Grammar, true);
                }
#endif
            }
        }
 public void Build(IReportData data)
 {
     foreach (var condition in data.Grammar.Conditions)
     {
         int i = condition.Index;
         string scanModeFileName = Path.GetFileName(fileName) + "_" + i + Path.GetExtension(fileName);
         string path = Path.Combine(data.DestinationDirectory, scanModeFileName);
         using (var graph = new GvGraphView(path))
         {
             var dfa = data.GetScannerAutomata(condition);
             dfa.DescribeGraph(graph);
         }
     }
 }
Ejemplo n.º 4
0
        public void Test()
        {
            var context = new SAdBLang();
            using (var interp = new Interpreter<SAdBLang>(context))
            {
                interp.Parse("d");
                Assert.IsTrue(context.IsFinalRuleCalledLast);
                Assert.IsTrue(context.WasMergeCalled);

                // with SPPF producer
                var sppf = interp.BuildTree("d");

                using (var graph = new GvGraphView(typeof(SAdBLang).Name + "_sppf.gv"))
                {
                    sppf.WriteGraph(graph, interp.Grammar, true);
                }
            }
        }
Ejemplo n.º 5
0
        public void Test2Sppf()
        {
            var filePath = DataSamples.CompileSample2FilePath;

            using (var source = new StreamReader(filePath))
            using (var interpreter = new Interpreter<ILLanguage>())
            {
                SppfNode sppf = interpreter.BuildTree(source, filePath);

                using (var graph = new GvGraphView("Cil_Sample2_sppf.gv"))
                {
                    var lang = Language.Get(typeof(ILLanguage));
                    sppf.WriteGraph(graph, lang.Grammar, true);
                }
            }
        }