Esempio n. 1
0
        public JsonTmDefinition ToJson(string name)
        {
            var j = new JsonTmDefinition();

            j.OriginalDefinition = FullDefinitionString;

            j.NonfinalStates = Q
                               .Where(p => Qa == null || p.Key != Qa.Name)
                               .Where(p => Qr == null || p.Key != Qr.Name)
                               .Select(p => p.Key)
                               .ToArray();
            if (Qa != null)
            {
                j.AcceptingState = Qa.Name;
            }
            if (Qr != null)
            {
                j.RefusingState = Qr.Name;
            }
            j.InitialState = Q0.Name;

            j.Sigma = Sigma.OrderBy(p => p.Key).Select(p => p.Value).ToArray();
            j.Gamma = Gamma.OrderBy(p => p.Key).Select(p => p.Value).ToArray();

            var delta = new List <JsonTmDefinition.Transition> ();
            var qs    = Q.Values
                        .Where(q => q.Delta != null)
                        .SelectMany(q => q.Delta);

            foreach (var ts in qs)
            {
                if (ts == null)
                {
                    continue;
                }
                var t = new JsonTmDefinition.Transition();
                t.From  = ts.Source.Name;
                t.Read  = Gamma[ts.Read];
                t.To    = ts.Next.Name;
                t.Write = Gamma[ts.Write];
                t.Dir   = ts.Direction == 0 ? "S" : ts.Direction == 1 ? "R" : "L";
                delta.Add(t);
            }
            j.Delta = delta.ToArray();

            j.SuggestedMacroSize = SuggestedMacroSize;

            j.Info_Name           = name;
            j.Info_Comment        = GetComments(FullDefinitionString).ToArray();
            j.Info_Url            = null;
            j.Info_ExpectedResult = null;

            return(j);
        }
Esempio n. 2
0
		public JsonTmDefinition ToJson (string name)
		{
			var j = new JsonTmDefinition ();

			j.OriginalDefinition = FullDefinitionString;

			j.NonfinalStates = Q
				.Where (p => Qa == null || p.Key != Qa.Name)
				.Where (p => Qr == null || p.Key != Qr.Name)
				.Select (p => p.Key)
				.ToArray ();
			if (Qa != null) {
				j.AcceptingState = Qa.Name;
			}
			if (Qr != null) {
				j.RefusingState = Qr.Name;
			}
			j.InitialState = Q0.Name;

			j.Sigma = Sigma.OrderBy (p => p.Key).Select (p => p.Value).ToArray ();
			j.Gamma = Gamma.OrderBy (p => p.Key).Select (p => p.Value).ToArray ();

			var delta = new List<JsonTmDefinition.Transition> ();
			var qs = Q.Values
				.Where (q => q.Delta != null)
				.SelectMany (q => q.Delta);
			foreach (var ts in qs) {
				if (ts == null) {
					continue;
				}
				var t = new JsonTmDefinition.Transition ();
				t.From = ts.Source.Name;
				t.Read = Gamma[ts.Read];
				t.To = ts.Next.Name;
				t.Write = Gamma[ts.Write];
				t.Dir = ts.Direction == 0 ? "S" : ts.Direction == 1 ? "R" : "L";
				delta.Add (t);
			}
			j.Delta = delta.ToArray ();

			j.SuggestedMacroSize = SuggestedMacroSize;

			j.Info_Name = name;
			j.Info_Comment = GetComments (FullDefinitionString).ToArray ();
			j.Info_Url = null;
			j.Info_ExpectedResult = null;

			return j;
		}