Пример #1
0
        public TdfaSimulationLexer(TextReader textSource, ScannerDescriptor descriptor)
        {
            this.text       = textSource.ReadToEnd();
            this.descriptor = descriptor;

            Dictionary <string, int> literalToAction = new Dictionary <string, int>();
            var root      = descriptor.MakeAst(literalToAction);
            var regTree   = new RegularTree(root);
            var algorithm = new RegularToTdfaAlgorithm(regTree, literalToAction);

            DescribeTdfa(algorithm.Data);
            this.tdfa = new TdfaSimulation(algorithm.Data);

            int count = descriptor.Matchers.Count;

            this.tokenFactories = new TokenFactoryDelegate[count];

            for (int i = 0; i != count; ++i)
            {
                if (descriptor.Matchers[i].Outcome != null)
                {
                    tokenFactories[i] = BuildTokenFactory(descriptor.Matchers[i]);
                }
            }
        }
        private static bool CompileTdfa(ILogging logging, Condition condition, out ITdfaData outcome)
        {
            var descr = ScannerDescriptor.FromScanRules(condition.Matchers, logging);

            var literalToAction = new Dictionary <string, int>();
            var ast             = descr.MakeAst(literalToAction);

            if (ast == null)
            {
                outcome = null;
                return(false);
            }

            var regTree = new RegularTree(ast);

            outcome = new RegularToTdfaAlgorithm(regTree, literalToAction).Data;
            condition.Joint.Add(outcome);

            return(true);
        }