예제 #1
0
 private void OpenGrammar()
 {
     if (openGrammarDialog.ShowDialog() == DialogResult.OK)
     {
         settings.LastGrammar = openGrammarDialog.FileName;
         SaveSettings();
         WriteLn("Reading file...");
         long t1 = DateTime.Now.Ticks;
         try
         {
             CGTReader reader = new CGTReader(openGrammarDialog.FileName);
             parser                = reader.CreateNewParser();
             parser.OnTokenRead   += new LALRParser.TokenReadHandler(TokenReadEvent);
             parser.OnShift       += new LALRParser.ShiftHandler(ShiftEvent);
             parser.OnReduce      += new LALRParser.ReduceHandler(ReduceEvent);
             parser.OnGoto        += new LALRParser.GotoHandler(GotoEvent);
             parser.OnAccept      += new LALRParser.AcceptHandler(AcceptEvent);
             parser.OnTokenError  += new LALRParser.TokenErrorHandler(TokenErrorEvent);
             parser.OnParseError  += new LALRParser.ParseErrorHandler(ParseErrorEvent);
             parser.OnCommentRead += new LALRParser.CommentReadHandler(CommentReadEvent);
             long t2 = DateTime.Now.Ticks;
             WriteLn(String.Format("Reading the Compiled Grammar Table File took {0}ms", (t2 - t1) / 10000));
         }
         catch (Exception e)
         {
             WriteLn(e.Message);
         }
     }
 }
예제 #2
0
    public void testCalithaEngine(string cgtFile, string sourceFile)
    {
        FileStream fs     = new FileStream(cgtFile, FileMode.Open, FileAccess.Read);
        CGTReader  reader = new CGTReader(fs);
        LALRParser parser = reader.CreateNewParser();

        parser.StoreTokens = LALRParser.StoreTokensMode.Never;
        fs.Close();

        FileStream   sourceStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read);
        StreamReader sr           = new StreamReader(sourceStream);
        String       source       = sr.ReadToEnd();

        parser.OnTokenError += new LALRParser.TokenErrorHandler(TokenErrorEvent);
        parser.OnParseError += new LALRParser.ParseErrorHandler(ParseErrorEvent);

        TimeSpan timeStart = new TimeSpan(DateTime.Now.Ticks);

        parser.Parse(source);

        /*
         * for (int i = 0; i < 1000; i++)
         * {
         *      parser.Parse(source);
         * }
         */
        TimeSpan timeEnd = new TimeSpan(DateTime.Now.Ticks);

        this.outputBox.AppendText("Took " + timeEnd.Subtract(timeStart).ToString() + "\n");
    }
예제 #3
0
        public void Start(string input)
        {
            CGTReader reader = new CGTReader(cgt);

            parser = reader.CreateNewParser();

            parser.OnTokenRead += OnRead;
            parser.OnShift     += OnSF;
            parser.OnAccept    += Parser_OnAccept;
            if (parser != null)
            {
                parser.Parse(input);
            }
        }
예제 #4
0
        private void Init(Stream stream)
        {
            CGTReader reader = new CGTReader(stream);

            parser = reader.CreateNewParser();
            parser.TrimReductions = false;
            parser.StoreTokens    = LALRParser.StoreTokensMode.NoUserObject;

            parser.OnReduce     += new LALRParser.ReduceHandler(ReduceEvent);
            parser.OnTokenRead  += new LALRParser.TokenReadHandler(TokenReadEvent);
            parser.OnAccept     += new LALRParser.AcceptHandler(AcceptEvent);
            parser.OnTokenError += new LALRParser.TokenErrorHandler(TokenErrorEvent);
            parser.OnParseError += new LALRParser.ParseErrorHandler(ParseErrorEvent);

            mContext = new Rule_Context();
        }
        private void Init(Stream stream, IScope pScope = null)
        {
            CGTReader reader = new CGTReader(stream);

            parser = reader.CreateNewParser();

            parser.StoreTokens    = LALRParser.StoreTokensMode.NoUserObject;
            parser.TrimReductions = false;
            parser.OnReduce      += new LALRParser.ReduceHandler(ReduceEvent);
            parser.OnTokenRead   += new LALRParser.TokenReadHandler(TokenReadEvent);
            parser.OnAccept      += new LALRParser.AcceptHandler(AcceptEvent);
            parser.OnTokenError  += new LALRParser.TokenErrorHandler(TokenErrorEvent);
            parser.OnParseError  += new LALRParser.ParseErrorHandler(ParseErrorEvent);

            /*
             * Configuration config = null;
             *
             * // check to see if config is already loaded
             * // if NOT then load default
             * try
             * {
             *  config = Configuration.GetNewInstance();
             *
             *  if (config == null)
             *  {
             *      Configuration.Load(Configuration.DefaultConfigurationPath);
             *  }
             * }
             * catch
             * {
             *  // It may throw an error in the Configuration.GetNewInstanc()
             *  // so try this from the default config path
             *  Configuration.Load(Configuration.DefaultConfigurationPath);
             * }*/


            if (pScope == null)
            {
                mContext = new Rule_Context();
            }
            else
            {
                mContext = new Rule_Context(pScope);
            }
        }
예제 #6
0
        private void Init(Stream stream)
        {
            CGTReader reader = new CGTReader(stream);

            parser = reader.CreateNewParser();
            parser.TrimReductions = false;
            parser.StoreTokens    = LALRParser.StoreTokensMode.NoUserObject;

            parser.OnTokenError += new LALRParser.TokenErrorHandler(TokenErrorEvent);
            parser.OnParseError += new LALRParser.ParseErrorHandler(ParseErrorEvent);

            this.lowerCasePrimitiveTypeEnumValues = new List <string>();
            this.autonumberedTypes = new List <PatternBufferType>();
            foreach (PrimitiveType pt in Enum.GetValues(typeof(PrimitiveType)))
            {
                lowerCasePrimitiveTypeEnumValues.Add(pt.ToString().ToLower());
            }
            this.error = null;
        }
        private void Init(Stream stream)
        {
            CGTReader reader = new CGTReader(stream);

            parser = reader.CreateNewParser();

            parser.StoreTokens    = LALRParser.StoreTokensMode.NoUserObject;
            parser.TrimReductions = false;
            parser.OnReduce      += new LALRParser.ReduceHandler(ReduceEvent);
            parser.OnTokenRead   += new LALRParser.TokenReadHandler(TokenReadEvent);
            parser.OnAccept      += new LALRParser.AcceptHandler(AcceptEvent);
            parser.OnTokenError  += new LALRParser.TokenErrorHandler(TokenErrorEvent);
            parser.OnParseError  += new LALRParser.ParseErrorHandler(ParseErrorEvent);

            Configuration config = null;

            // check to see if config is already loaded
            // if NOT then load default
            try
            {
                config = Configuration.GetNewInstance();

                if (config == null)
                {
                    Configuration.Load(Configuration.DefaultConfigurationPath);
                }
            }
            catch
            {
                // It may throw an error in the Configuration.GetNewInstanc()
                // so try this from the default config path
                Configuration.Load(Configuration.DefaultConfigurationPath);
            }

            mContext = new Rule_Context();

            // this is done to ensure that the encourage copying of the Epi.Analysis.Statistics dll
            // to the build folder;
            //System.Console.WriteLine(Epi.Analysis.Statistics.Frequency.Equals(null,null));
        }
예제 #8
0
        public static LALRParser GoldParser(string filename)
        {
            var    assembly    = IntrospectionExtensions.GetTypeInfo(typeof(SharedAssets)).Assembly;
            Stream assetStream = assembly.GetManifestResourceStream("KaemikaAssets.Assets." + filename);

            if (assetStream == null)
            {
                throw new AssetError("GoldParser file not found: " + filename);
            }
            try {
                MemoryStream cgtStream = new MemoryStream();
                assetStream.CopyTo(cgtStream);  // copy Stream to a MemoryStream because CGTReader will try to ask for the length of Stream, and a plain Stream does not suport that
                cgtStream.Position = 0;         // after CopyTo the memorystream position is at the end, so reset it
                //numberFormatInfo = new NumberFormatInfo();
                //numberFormatInfo.NumberDecimalSeparator = ".";
                CGTReader  reader = new CGTReader(cgtStream);
                LALRParser parser = reader.CreateNewParser();
                parser.TrimReductions = false;
                parser.StoreTokens    = LALRParser.StoreTokensMode.NoUserObject;
                return(parser);
            } catch (Exception ex) {
                throw new AssetError("Parser loading failed: " + ex.Message);
            }
        }
예제 #9
0
 private void OpenGrammar()
 {
     if (openGrammarDialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             CGTReader reader = new CGTReader(openGrammarDialog.FileName);
             parser                = reader.CreateNewParser();
             parser.OnTokenRead   += new LALRParser.TokenReadHandler(TokenReadEvent);
             parser.OnShift       += new LALRParser.ShiftHandler(ShiftEvent);
             parser.OnReduce      += new LALRParser.ReduceHandler(ReduceEvent);
             parser.OnGoto        += new LALRParser.GotoHandler(GotoEvent);
             parser.OnAccept      += new LALRParser.AcceptHandler(AcceptEvent);
             parser.OnTokenError  += new LALRParser.TokenErrorHandler(TokenErrorEvent);
             parser.OnParseError  += new LALRParser.ParseErrorHandler(ParseErrorEvent);
             parser.OnCommentRead += new LALRParser.CommentReadHandler(CommentReadEvent);
             MessageBox.Show("Reading file compiled!");
         }
         catch (Exception e)
         {
             MessageBox.Show("Error: " + e.ToString());
         }
     }
 }