public static void Serialize(BinaryWriter writer, LALRParser target)
 {
     writer.Write(target.leaveOpen);
     SaveLoader.WriteGrammar(writer, target.m_grammar);
     SaveLoader.WriteGTB(target.gtb, writer);
     SaveLoader.WriteATB(target.atb, writer);
 }
        private static int GetCapacity(LALRParser target)
        {
            Grammar g = target.m_grammar;

            GItem[] gts = g.m_items;

            int x = 0, max = gts.Length;

            int size = 17 + max * 5 + g.m_nonterminals.Length * 4; // bool + ushort * 4 + int * 2 + (sizeof(ushort) + sizeof(byte)) * N

            for (; x < max; x++)
            {
                size += gts[x].express.Length * 4;
            }

            Map <int>[] gtb = target.gtb;
            max = gtb.Length;

            size += max * 2;
            for (x = 0; x < max; x++)
            {
                size += gtb[x].Count * 8;
            }

            Map <TableItem>[] atb = target.atb;
            max = atb.Length;

            size += max * 2;
            for (x = 0; x < max; x++)
            {
                size += atb[x].Count * 12;
            }

            return(size);
        }
        public static byte[] ToByteArray(LALRParser target)
        {
            MemoryStream ms = new MemoryStream(GetCapacity(target));
            BinaryWriter wr = new BinaryWriter(ms, Encoding.ASCII, false);

            Serialize(wr, target);

            byte[] result = ms.ToArray();
            wr.Dispose();

            return(result);
        }
예제 #4
0
        /// <exception cref="ArgumentNullException">rootDirectory is null or empty or whitespace</exception>
        public ScriptLoader(Scanner scanner, PreProcessor preprocessor, LALRParser parser, string rootDirectory) : this()
        {
            if (string.IsNullOrWhiteSpace(rootDirectory))
            {
                throw new ArgumentNullException(nameof(rootDirectory));
            }
            if (!Directory.Exists(rootDirectory))
            {
                Directory.CreateDirectory(rootDirectory);
            }

            m_path         = rootDirectory;
            m_scanner      = scanner;
            m_preprocessor = preprocessor;
            m_parser       = parser;
        }
예제 #5
0
        protected virtual void Dispose(bool disposing)
        {
            if (m_preprocessor != null)
            {
                m_preprocessor.Dispose();
                m_preprocessor = null;
            }

            if (m_path != null)
            {
                m_scanner.Dispose();
                m_parser.Dispose();

                m_scanner = null;
                m_parser  = null;

                m_path  = null;
                m_asmbd = null;
                m_modbd = null;
            }
        }
 public ILScriptLoader(Scanner scanner, PreProcessor preprocessor, LALRParser parser, string rootDirectory) : base(scanner, preprocessor, parser, rootDirectory)
 {
 }