Пример #1
0
        private static AutomataType CreateAutomataSeq(RegExpSeq Seq)
        {
            AutomataType type;
            short        head;
            short        tail;
            short        num4 = (short)(Seq.Count() - 1);

            for (short i = 0; i <= num4; i = (short)(i + 1))
            {
                RegExpSeq  seq  = Seq;
                short      num5 = i;
                RegExpItem item = seq[num5];
                seq[num5] = item;
                AutomataType type3 = CreateAutomataItem(item);
                if (i == 0)
                {
                    head = type3.Head;
                    tail = type3.Tail;
                }
                else
                {
                    NFA[tail].AddLambdaEdge(type3.Head);
                    tail = type3.Tail;
                }
            }
            type.Head = head;
            type.Tail = tail;
            return(type);
        }
Пример #2
0
 public static void EnsureAutomataIsOfType(this Automata automata, AutomataType automataType, Exception throwException)
 {
     ValidationUtils.EnsureEquals(
         automataType.ToString(),
         automata.GetAutomataType().ToString(),
         throwException
         );
 }
Пример #3
0
    private void Start()
    {
        Instance     = this;
        _connections = new List <Vector2Int>();
        automataType = AutomataType.dfa;

        _inputChecker = GetComponent <InputStringCheck>();

        ConnectionEvents.Instance.OnSecondStateSelected += UpdateLocalConnections;
    }
Пример #4
0
        public static void CreateNFAStates(SymbolBuild Sym)
        {
            short target = (short)AddState();
            short num3   = (short)AddState();
            short num4   = (short)(Sym.RegularExp.Count() - 1);

            for (short i = 0; i <= num4; i = (short)(i + 1))
            {
                RegExpSeq    seq  = Sym.RegularExp[i];
                AutomataType type = CreateAutomataSeq(seq);
                NFA[target].AddLambdaEdge(type.Head);
                NFA[type.Tail].AddLambdaEdge(num3);
                NFA[type.Tail].AcceptList.Add(Sym.TableIndex, seq.Priority);
            }
            NFA[Root].AddLambdaEdge(target);
        }
Пример #5
0
        public override String ToString()
        {
            String newLine        = Environment.NewLine;
            String tab            = "\t";
            String quoteChar      = "'";
            String commaSeparator = ", ";
            String type           = tab + quoteChar + AutomataType.ToString() + quoteChar;
            String states         = "";
            String symbols        = "";
            String initialState   = tab + quoteChar + InitialState?.ToString() + quoteChar;
            String finalStates    = tab;
            String transitions    = "";

            States.ForEach(
                x => states += quoteChar + x.ToString() + quoteChar + commaSeparator
                );
            if (states.Length >= 3)
            {
                states = states.Substring(0, states.Length - 2);
            }
            Symbols.ForEach(
                x => symbols += quoteChar + x + quoteChar + commaSeparator
                );
            if (symbols.Length >= 3)
            {
                symbols = symbols.Substring(0, symbols.Length - 2);
            }
            FinalStates.ForEach(
                x => finalStates += quoteChar + x.ToString() + quoteChar + commaSeparator
                );
            if (finalStates.Length >= 3)
            {
                finalStates = finalStates.Substring(0, finalStates.Length - 2);
            }
            Transitions.ForEach(
                x => transitions += tab + quoteChar + x.ToString() + quoteChar + newLine
                );

            return
                ($"Type: {newLine}{type}{newLine}" +
                 $"States: {newLine}{tab}{states}{newLine}" +
                 $"Symbols: {newLine}{tab}{symbols}{newLine}" +
                 $"InitialState: {newLine}{initialState}{newLine}" +
                 $"FinalStates: {newLine}{finalStates}{newLine}" +
                 $"Transitions: {newLine}{transitions}");
        }
Пример #6
0
        private static AutomataType CreateSubAutomata(RegExp Exp)
        {
            AutomataType type3;
            short        num    = (short)AddState();
            short        target = (short)AddState();
            short        num4   = (short)(Exp.Count() - 1);

            for (short i = 0; i <= num4; i = (short)(i + 1))
            {
                RegExpSeq    seq  = Exp[i];
                AutomataType type = CreateAutomataSeq(seq);
                NFA[num].AddLambdaEdge(type.Head);
                NFA[type.Tail].AddLambdaEdge(target);
            }
            type3.Head = num;
            type3.Tail = target;
            return(type3);
        }
Пример #7
0
    private void Start()
    {
        _type                 = AutomataManager.automataType;
        _inputField           = GetComponent <InputField>();
        _inputRect            = GetComponent <RectTransform>();
        _size                 = _inputRect.sizeDelta;
        _inputRect.localScale = Vector3.one;

        if (_inputCheck == null)
        {
            if (_type == AutomataType.dfa)
            {
                _inputCheck = new SingleTagProcessor();
            }
            else if (_type == AutomataType.DPDA || _type == AutomataType.Turing)
            {
                _inputCheck = new TripletTagProcessor();
            }
        }
        gameObject.SetActive(false);

        ConnectionEvents.Instance.OnEditMode    += OnActiveEditMode;
        BuildStateEvents.Instance.OnDeleteState += DestroyThisWhenStateDeleted;
    }
Пример #8
0
        private static Automata CreateNewAutomataFromTuple(
            Automata automata,
            AutomataType newType,
            Tuple <List <GroupedState>, List <Transition> > aggregationTuple
            )
        {
            var      epsilonStates      = aggregationTuple.Item1;
            var      epsilonTransitions = aggregationTuple.Item2;
            Automata newAutomata        = DeepCloneAutomata(automata);

            newAutomata.SetAutomataType(newType);
            newAutomata.SetStates(epsilonStates.ToArray());
            newAutomata.SetTransitions(epsilonTransitions.ToArray());
            newAutomata.SetInitialState(
                epsilonStates.Where(
                    x => x.GetSubStates().ToList().Any(
                        y => y.Name == automata.GetInitialState().Name
                        )
                    ).FirstOrDefault()
                );
            newAutomata.RefreshFinalStates();

            return(newAutomata);
        }
Пример #9
0
 public void SetAutomataType(AutomataType automataType)
 {
     AutomataType = automataType;
 }
Пример #10
0
        private static AutomataType CreateAutomataItem(RegExpItem Item)
        {
            AutomataType type;
            int          head;
            int          num3;
            int          num4;
            int          tail;

            if (Item.Data is RegExp)
            {
                RegExpItem item2 = Item;
                RegExp     data  = (RegExp)item2.Data;
                item2.Data = data;
                AutomataType type3 = CreateSubAutomata(data);
                head = type3.Head;
                tail = type3.Tail;
                num3 = head;
                num4 = tail;
            }
            else if (!(Item.Data is SetItem))
            {
                BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Invalid internal token at CreateAutomataItem(): " + Versioned.TypeName(RuntimeHelpers.GetObjectValue(Item.Data)));
            }
            else
            {
                CharacterSetBuild characters;
                SetItem           item = (SetItem)Item.Data;
                switch (item.Type)
                {
                case SetItem.SetType.Chars:
                    characters = (CharacterSetBuild)item.Characters;
                    head       = AddState();
                    tail       = AddState();
                    NFA[head].AddEdge(characters, tail);
                    num3 = head;
                    num4 = tail;
                    break;

                case SetItem.SetType.Name:
                    characters = (CharacterSetBuild)BuilderApp.GetCharacterSet(item.Text);
                    if (characters == null)
                    {
                        BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Unknown user-defined set: {" + item.Text + "}");
                        break;
                    }
                    tail = AddState();
                    head = AddState();
                    NFA[head].AddEdge(characters, tail);
                    num3 = head;
                    num4 = tail;
                    break;

                case SetItem.SetType.Sequence:
                {
                    int num6;
                    head = AddState();
                    tail = head;
                    string text = item.Text;
                    short  num7 = (short)(text.Length - 1);
                    for (short i = 0; i <= num7; i = (short)(i + 1))
                    {
                        num6 = tail;
                        tail = AddState();
                        NFA[num6].AddEdge(new CharacterSetBuild(Conversions.ToString(text[i])), tail);
                    }
                    num3 = num6;
                    num4 = tail;
                    break;
                }

                default:
                    BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Invalid internal token at CreateAutomataItem(): " + Versioned.TypeName(RuntimeHelpers.GetObjectValue(Item.Data)));
                    break;
                }
            }
            if ((num3 == 0) | (num4 == 0))
            {
                Debug.WriteLine("ERROR: BAD KLEENE DATA");
            }
            switch (Item.Kleene)
            {
            case "*":
                NFA[num3].AddLambdaEdge(num4);
                NFA[num4].AddLambdaEdge(num3);
                break;

            case "+":
                NFA[num4].AddLambdaEdge(num3);
                break;

            case "?":
                NFA[num3].AddLambdaEdge(num4);
                break;
            }
            type.Head = (short)head;
            type.Tail = (short)tail;
            return(type);
        }
Пример #11
0
 public FiniteAutomata(AutomataType type, List<char> chars)
 {
     this.type = type;
     alphabet = chars;
 }
Пример #12
0
 public static String SerializeType(AutomataType type)
 {
     return(type.ToString());
 }