Пример #1
0
        public static DFAModel CreateDFAModel(RegularExpression regex)
        {
            DFAModel model = new DFAModel();

            model.regexCollection.Add(regex);
            model.CreateDFAModel();
            return(model);
        }
Пример #2
0
        public ScannerInfo GenerateData()
        {
            if (isGenerate)
            {
                return(this);
            }
            dfa.CreateDFAModel();

            faState = new List <Token>();

            for (int i = 0; i < dfa.DFAList.Count; i++)
            {
                faState.Add(null);
                if (dfa.DFAList[i].isEndState)
                {
                    faState[i]             = new Token();
                    faState[i].Describtion = dfa.DFAList[i].Describtion;
                    faState[i].status      = dfa.DFAList[i].index;
                }
            }

            var inputSet = new List <int>();

            dfaTable = new int[faState.Count, 256];

            //too stupid way to init inputSet
            for (int i = 0; i < dfa.DFAList.Count; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    dfaTable[i, j] = -1;
                }
            }
            //init hash table
            hash = new int[256];
            for (int i = 0; i < 256; i++)
            {
                hash[i] = -1;
            }

            for (int i = 0; i < faState.Count; i++)
            {
                var t = dfa.DFAList[i];
                foreach (var x in t.Lead)
                {
                    if (!inputSet.Contains(x.statement))
                    {
                        inputSet.Add(x.statement);
                    }
                    dfaTable[i, x.statement] = x.lead.Id;
                }
            }

            //trying to shorten with the method below
            isGenerate = true;
            compressDFA(inputSet);
            return(this);
        }