Пример #1
0
        private ulong ReadEncSymbWord()
        {
            ulong encWord = 0;

            for (int i = 0; i < 10; i++)
            {
                if (NextIsLower())
                {
                    byte code = SymbTableFastCache.EncodedLetter(Read());
                    encWord = (encWord << 6) + code;
                }
                else if (NextIs('_'))
                {
                    Skip();
                    if (NextIsLower())
                    {
                        byte code = SymbTableFastCache.EncodedUnderscoredLetter(Read());
                        encWord = (encWord << 6) + code;
                    }
                    else if (NextIsDigit())
                    {
                        encWord = (encWord << 6) + SymbTableFastCache.ENCODED_UNDERSCORE;
                    }
                    else
                    {
                        throw Fail();
                    }
                }
                else if (NextIsDigit())
                {
                    byte code = SymbTableFastCache.EncodedDigit(Read());
                    encWord = (encWord << 6) + code;
                }
                else
                {
                    return(encWord);
                }
            }
            return(encWord);
        }
Пример #2
0
        public ushort ReadSymbol()
        {
            Debug.Assert(NextIsLower());

            // long encWord1 = SymbTableFastCache.EncodedLetter(Read());
            // for (int i=0 ; i < 9 ; i++) {
            //   if (NextIsLower()) {
            //     int code =  SymbTableFastCache.EncodedLetter(Read());
            //     encWord1 = (encWord1 << 6) + code;
            //   }
            //   else if (NextIs('_')) {
            //     Skip();
            //     if (NextIsLower()) {
            //       int code = SymbTableFastCache.EncodedUnderscoredLetter(Read());
            //       encWord1 = (encWord1 << 6) + code;
            //     }
            //     else if (NextIsDigit()) {
            //       encWord1 = (encWord1 << 6) + SymbTableFastCache.ENCODED_UNDERSCORE;
            //     }
            //     else
            //       throw Fail();
            //   }
            //   else if (NextIsDigit()) {
            //     int code = SymbTableFastCache.EncodedDigit(Read());
            //     encWord1 = (encWord1 << 6) + code;
            //   }
            //   else {
            //     return SymbTableFastCache.EncToIdx(encWord1);
            //   }
            // }

            // if (!NextIsAlphaNum() & !NextIs('_'))
            //   return SymbTableFastCache.EncToIdx(encWord1);

            // long encWord2 = 0;
            // for (int i=0 ; i < 10 ; i++) {
            //   if (NextIsLower()) {
            //     int code =  SymbTableFastCache.EncodedLetter(Read());
            //     encWord2 = (encWord2 << 6) + code;
            //   }
            //   else if (NextIs('_')) {
            //     Skip();
            //     if (NextIsLower()) {
            //       int code = SymbTableFastCache.EncodedUnderscoredLetter(Read());
            //       encWord2 = (encWord2 << 6) + code;
            //     }
            //     else if (NextIsDigit()) {
            //       encWord2 = (encWord2 << 6) + SymbTableFastCache.ENCODED_UNDERSCORE;
            //     }
            //     else
            //       throw Fail();
            //   }
            //   else if (NextIsDigit()) {
            //     int code = SymbTableFastCache.EncodedDigit(Read());
            //     encWord2 = (encWord2 << 6) + code;
            //   }
            //   else {
            //     return SymbTableFastCache.EncToIdx(encWord1, encWord2);
            //   }
            // }

            // if (!NextIsAlphaNum() & !NextIs('_'))
            //   return SymbTableFastCache.EncToIdx(encWord1, encWord2);


            ulong encWord1 = ReadEncSymbWord();

            if (!NextIsAlphaNum() & !NextIs('_'))
            {
                return(SymbTableFastCache.EncToIdx(encWord1));
            }

            ulong encWord2 = ReadEncSymbWord();

            if (!NextIsAlphaNum() & !NextIs('_'))
            {
                return(SymbTableFastCache.EncToIdx(encWord1, encWord2));
            }

            ulong encWord3 = ReadEncSymbWord();

            if (!NextIsAlphaNum() & !NextIs('_'))
            {
                return(SymbTableFastCache.EncToIdx(encWord1, encWord2, encWord3));
            }

            ulong[] encWords = new ulong[8];
            encWords[0] = encWord1;
            encWords[1] = encWord2;
            encWords[2] = encWord3;

            for (int i = 3; i < 64; i++)
            {
                if (i >= encWords.Length)
                {
                    encWords = Array.Extend(encWords, 2 * encWords.Length);
                }
                encWords[i] = ReadEncSymbWord();
                if (!NextIsAlphaNum() & !NextIs('_'))
                {
                    return(SymbTableFastCache.EncToIdx(encWords, i + 1));
                }
            }

            // The symbol was too long, we give up
            throw Fail();
        }