Пример #1
0
        public ShiftReduceParser()
        {
            _stateStack    = new ParserStack <State>();
            _valueStack    = new ParserStack <TValue>();
            _locationStack = new ParserStack <TLocation>();

            if (_tables == null)
            {
                lock (_tablesLock) {
                    if (_tables == null)
                    {
                        ParserTables tables = new ParserTables();
                        Initialize(tables);
#if DEBUG
                        InitializeMetadata(tables);
                        InitializeRulesMetadata(tables);
#endif
                        Thread.MemoryBarrier();
                        _tables = tables;
                    }
                }
            }

            _states = _tables.States;
            _ruleLhsNonTerminals = _tables.RuleLhsNonTerminals;
            _ruleRhsLengths      = _tables.RuleRhsLengths;
            _errorToken          = _tables.ErrorToken;
            _eofToken            = _tables.EofToken;
        }
Пример #2
0
        private void InitializeTables()
        {
            _stack = new ParserStack <State, TValue, TLocation>();

            if (_tables == null)
            {
                lock (_tablesLock) {
                    if (_tables == null)
                    {
                        Debug.Assert(typeof(TLocation).IsValueType);

                        ParserTables tables = new ParserTables();
                        InitializeGeneratedTables(tables);
#if DEBUG
                        InitializeMetadata(tables);
                        InitializeRulesMetadata(tables);
#endif
                        Thread.MemoryBarrier();
                        _tables = tables;
                    }
                }
            }

            _states     = _tables.States;
            _rules      = _tables.Rules;
            _errorToken = _tables.ErrorToken;
            _eofToken   = _tables.EofToken;
        }