Esempio n. 1
0
        public byte[] Uncompress(byte[] compressed)
        {
            var reader = new BinReader(compressed);

            var byteCount = reader.ReadInt32();
            var bytes     = new byte[byteCount];

            bool zero = true;
            var  pos  = 0;

            while (reader.CanRead)
            {
                if (zero)
                {
                    var zeroCount = reader.ReadInt32();
                    for (var i = 0; i < zeroCount; ++i)
                    {
                        bytes[pos++] = 0;
                    }
                    zero = false;
                }
                else
                {
                    var count = reader.ReadInt32();
                    for (var i = 0; i < count; ++i)
                    {
                        bytes[pos++] = reader.ReadByte();
                    }
                    zero = true;
                }
            }

            return(bytes);
        }
Esempio n. 2
0
        public IParseTable Read()
        {
            var numberOfStates       = this.reader.ReadInt32();
            var numberOfTerminals    = this.reader.ReadInt32();
            var numberOfSymbols      = this.reader.ReadInt32();
            var numberOfNonterminals = numberOfSymbols - numberOfTerminals;

            var compactTerminalCount = this.reader.ReadInt32();
            var compactTerminals     = new int[compactTerminalCount][];

            for (var i = 0; i < compactTerminalCount; ++i)
            {
                var compacts = new int[numberOfTerminals];
                for (var c = 0; c < numberOfTerminals; ++c)
                {
                    compacts[c] = this.reader.ReadInt32();
                }
                compactTerminals[i] = compacts;
            }

            var compactNonterminalCount = this.reader.ReadInt32();
            var compactNonterminals     = new int[compactNonterminalCount][];

            for (var i = 0; i < compactNonterminalCount; ++i)
            {
                var compacts = new int[numberOfNonterminals];
                for (var c = 0; c < numberOfNonterminals; ++c)
                {
                    compacts[c] = this.reader.ReadInt32();
                }
                compactNonterminals[i] = compacts;
            }

            var states = new CompactState[numberOfStates];

            for (var i = 0; i < states.Length; ++i)
            {
                var terminalMin      = reader.ReadInt32();
                var terminalIndex    = reader.ReadInt32();
                var nonterminalMin   = reader.ReadInt32();
                var nonterminalIndex = reader.ReadInt32();

                var state = new CompactState(
                    terminalMin, compactTerminals[terminalIndex],
                    nonterminalMin, compactNonterminals[nonterminalIndex]);

                states[i] = state;
            }

            return(new CompactParseTable(states, numberOfTerminals, numberOfSymbols));
        }