示例#1
0
        /// <summary>
        /// Loads grammar from the binary reader.
        /// </summary>
        private void Load(LoadContext context)
        {
            string headerString = context.ReadHeaderString();
//			Trace.WriteLine(headerString, "Reading header");
            Match headerMatch = FileHeader.Match(headerString);

            if (!headerMatch.Success)
            {
                throw new FileLoadException("The File Header is invalid or unsupported: " + headerString);
            }
            switch (headerMatch.Groups["version"].Value)
            {
            case "1.0":
                fileVersion = CgtVersion.V1_0;
                break;

            case "5.0":
                fileVersion = CgtVersion.V5_0;
                break;

            default:
                throw new FileLoadException(string.Format("The file format version {0} is not unsupported", headerMatch.Groups["version"].Value));
            }
            while (context.HasMoreData())
            {
                CgtRecordType recordType = context.ReadNextRecord();
///				Trace.WriteLine(recordType, "Reading record");
                switch (recordType)
                {
                case CgtRecordType.Parameters:
                    ReadHeader(context);
                    break;

                case CgtRecordType.Property:
                    ReadProperty(context);
                    break;

                case CgtRecordType.Groups:
                    ReadGroup(context);
                    break;

                case CgtRecordType.TableCountsEnhanced:
                    ReadTableCounts(context, true);
                    break;

                case CgtRecordType.TableCounts:
                    ReadTableCounts(context, false);
                    break;

                case CgtRecordType.Initial:
                    ReadInitialStates(context);
                    break;

                case CgtRecordType.Symbols:
                    ReadSymbol(context);
                    break;

                case CgtRecordType.Charsets:
                    ReadCharset(context);
                    break;

                case CgtRecordType.PackedCharsets:
                    if (fileVersion == CgtVersion.V1_0)
                    {
                        ReadPackedCharset(context);
                    }
                    else
                    {
                        ReadRangeCharset(context);
                    }
                    break;

                case CgtRecordType.Rules:
                    ReadRule(context);
                    break;

                case CgtRecordType.DfaStates:
                    ReadDfaState(context);
                    break;

                case CgtRecordType.LRStates:
                    ReadLRState(context);
                    break;

                default:
                    throw new FileLoadException("Invalid record type");
                }
            }
            dfaInitialState  = dfaStateTable[context.DfaInitialStateIndex];
            startSymbol      = symbolTable[context.StartSymbolIndex];
            lalrInitialState = lalrStateTable[context.LrInitialState];
            FixupGroups(context);
        }