Beispiel #1
0
        public ParserCompiler(TokenReader <TTok> reader)
        {
            Rules = new RuleSet(
                typeof(TSelf),
                typeof(TTok),
                typeof(TResult),
                (int)(object)reader.EndOfStream,
                reader.PublicChildren.ToDictionary(
                    kv => (int)(object)kv.Key,
                    kv => (IReadOnlyList <int>)kv.Value.Select(i => (int)(object)i).ToArray()));

            var smb = new StateMachineBuilder(Rules);

            _initialState = smb.Build();
            _actions      = smb.Actions;

            // File.WriteAllText("C:/LokadData/priceforge/slr.txt", smb.Describe());

            foreach (var r in Rules.Rules)
            {
                var t = r.Type;
                if (!_stacks.ContainsKey(t))
                {
                    _stacks.Add(t, Expression.Parameter(typeof(Stack <>).MakeGenericType(t), "stack_" + t.Name));
                }
            }
        }
Beispiel #2
0
        public ParseContextEvaluator(
            ITokenNamer <TTok> namer,
            TokenReader <TTok> reader,
            Func <int, TCtxt> toContext)
        {
            Rules = new RuleSet(
                typeof(TGrammar),
                typeof(TTok),
                typeof(TRez),
                (int)(object)reader.EndOfStream,
                reader.PublicChildren.ToDictionary(
                    kv => (int)(object)kv.Key,
                    kv => (IReadOnlyList <int>)kv.Value.Select(i => (int)(object)i).ToArray()));

            var smb = new StateMachineBuilder(Rules);

            _namer         = namer;
            _initialState  = smb.Build();
            _actions       = smb.Actions;
            _stateContexts = smb.TagContexts.Select(arr => arr.Select(toContext).ToArray()).ToArray();
        }