Beispiel #1
0
        private void ParseSource()
        {
            if (parser != null)
            {
                parser.TrimReductions = settings.TrimReductions;
                errors = 0;
                parseActionsView.Items.Clear();
                parseTreeView.Nodes.Clear();
                tabControl.SelectedIndex = 1;

                //reader.LALRParser.Parse("abc 123 a34   (*@@@@@ *) last	text");
                //parser.Parse("aaa//comment1\nbbb\n//comm(*ent*)2\nccc");
                WriteLn("Parsing source...");
                long t1 = DateTime.Now.Ticks;
                try
                {
                    string str = sourceTextBox.Text;
                    //str = str.Replace("\n","\r\n");
                    parser.Parse(str);

                    long t2 = DateTime.Now.Ticks;
                    WriteLn(String.Format("Parsing the source took {0}ms", (t2 - t1) / 10000));
                }
                catch (System.ApplicationException e)
                {
                    WriteLn(e.Message);
                    AddViewItem("Internal error", null, "View log for details", "", "", 5);
                }
            }
        }
Beispiel #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");
    }
 public void Parse(string source)
 {
     try
     {
         parser.TrimReductions = true;
         this.commandText      = source;
         this.IsExecuteMode    = false;
         parser.TrimReductions = true;
         parser.Parse(source);
     }
     catch (InvalidOperationException ex)
     {
         if (!ex.Message.ToUpperInvariant().Contains("STACK EMPTY"))
         {
             throw ex;
         }
     }
 }
 public void Parse(string source)
 {
     try
     {
         this.mContext.AssignVariableCheck = new Dictionary <string, string>();
         this.commandText      = source;
         this.IsExecuteMode    = false;
         parser.TrimReductions = true;
         parser.Parse(source);
         this.mContext.AssignVariableCheck = null;
     }
     catch (InvalidOperationException ex)
     {
         if (!ex.Message.ToUpper().Contains("STACK EMPTY"))
         {
             throw ex;
         }
     }
 }
Beispiel #5
0
        public void Parse(string source)
        {
            try
            {
                this.RuleContext.CommandVariableCheck = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

                this.commandText      = source;
                this.IsExecuteMode    = false;
                parser.TrimReductions = true;
                parser.Parse(source);

                this.RuleContext.CommandVariableCheck = null;
            }
            catch (InvalidOperationException ex)
            {
                if (!ex.Message.ToUpperInvariant().Contains("STACK EMPTY"))
                {
                    throw ex;
                }
            }
        }
Beispiel #6
0
        public void SearchFor(string searchTerm)
        {
            LALRParser lalrParser = GrammarReader.CreateNewParser();

            _wiqlBuilder    = new WiqlBuilder();
            _fieldName      = "";
            _comparisonType = FieldComparison.Contains;

            lalrParser.OnTokenRead  += new LALRParser.TokenReadHandler(lalrParser_OnTokenRead);
            lalrParser.OnParseError += new LALRParser.ParseErrorHandler(lalrParser_OnParseError);
            lalrParser.OnTokenError += new LALRParser.TokenErrorHandler(lalrParser_OnTokenError);
            lalrParser.Parse(searchTerm);
        }
Beispiel #7
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);
            }
        }
Beispiel #8
0
        public PatternBufferSchema Parse(string source)
        {
            NonterminalToken    token  = parser.Parse(source);
            PatternBufferSchema schema = null;

            if (this.error == null && token != null)
            {
                schema = (PatternBufferSchema)CreateObject(token);
            }
            if (this.error != null)
            {
                throw new PatternBufferSchemaException(this.error);
            }
            return(schema);
        }
Beispiel #9
0
        /*
         * public EpiMenuInterpreterParser(Stream stream, IEnterCheckCode pEnterCheckCodeInterface, Rule_Context.eRunMode pRunMode)
         * {
         *  Init(stream);
         *  this.EnterCheckCodeInterface = pEnterCheckCodeInterface;
         *  this.RunMode = pRunMode;
         * }
         *
         * public EpiMenuInterpreterParser(Stream stream, IAnalysisCheckCode pAnalysisCheckCodeInterface, Rule_Context.eRunMode pRunMode)
         * {
         *  Init(stream);
         *  this.AnalysisCheckCodeInterface = pAnalysisCheckCodeInterface;
         *  this.RunMode = pRunMode;
         * }*/

        public void Parse(string source)
        {
            try
            {
                this.commandText = source;
                parser.Parse(source);
            }
            catch (InvalidOperationException ex)
            {
                if (!ex.Message.ToUpperInvariant().Contains("STACK EMPTY"))
                {
                    throw ex;
                }
            }
        }
Beispiel #10
0
        public override bool Parse(string source, out IReduction reduction)
        {
            NonterminalToken token = parser.Parse(source);

            if (token == null)
            {
                reduction = null;
                return(false);
            }
            else
            {
                reduction = new CalithaReduction(token);
                return(true);
            }
        }
Beispiel #11
0
        Linq.Expression _Parse(string input, IDictionary <string, Type> availableFields)
        {
            Reset(availableFields);

            var token = _Parser.Parse(input);

            Debug.Assert(token != null || Errors.Count > 0);

            //Failed
            if (token == null)
            {
                return(null);
            }

            var expression = (Linq.Expression)token.UserObject;

            ResultType  = expression.Type;
            Description = expression.ToString();
            return(expression);
        }
Beispiel #12
0
 private void ParseSource()
 {
     if (parser != null)
     {
         errors = 0;
         parseActionsView.Items.Clear();
         parseTreeView.Nodes.Clear();
         tabControl.SelectedIndex = 1;
         try
         {
             string str = sourceTextBox.Text;
             parser.Parse(str);
         }
         catch (System.ApplicationException e)
         {
             MessageBox.Show("Error: " + e.ToString());
             AddViewItem("Internal error", null, "View log for details", "", "", 5);
         }
     }
 }