Exemplo n.º 1
0
        private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
        {
            string message = "Token error with input: '" + args.Token.ToString() + "'";

            //todo: Report message to UI?
            lstError.Items.Add(message);
        }
Exemplo n.º 2
0
 private void AcceptEvent(LALRParser parser, AcceptEventArgs args)
 {
     /*** MODIFICAÇÕES ***/
     _mainForm.setLeituraState(true);
     _mainForm.setSyntaxState(_errorList.Count == 0);
     //MessageBox.Show("The file has been read succesfully");
     /*** MODIFICAÇÕES ***/
 }
Exemplo n.º 3
0
        private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
        {
            string message = "Parse error caused by token: ' " + args.UnexpectedToken.ToString() + " ' " + " in line : " + args.UnexpectedToken.Location.LineNr;

            //todo: Report message to UI?
            lstError.Items.Add(message);
            string message2 = "excepted token: '" + args.ExpectedTokens.ToString() + "'";

            lstError.Items.Add(message2);
        }
Exemplo n.º 4
0
 private void AcceptEvent(LALRParser parser, AcceptEventArgs args)
 {
     //todo: Use your fully reduced args.Token.UserObject
     try
     {
         resultado = Convert.ToString(args.Token.UserObject);
     }
     catch
     {
     }
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 private static void P_OnAccept(com.calitha.goldparser.LALRParser parser, com.calitha.goldparser.AcceptEventArgs args)
 {
     //   Console.WriteLine(args.Token.Rule.Lhs.Name);
     foreach (var t in args.Token.Tokens)
     {
         //var s= (find(t));
         FillTreeView(null, t);
         //     FillTreeView(args.Token,t);
     }
     //  Fx();
     // throw new NotImplementedException();
 }
Exemplo n.º 7
0
 private void ReduceEvent(LALRParser parser, ReduceEventArgs args)
 {
     try
     {
         args.Token.UserObject = CreateObject(args.Token);
     }
     catch (Exception e)
     {
         args.Continue = false;
         //todo: Report message to UI?
     }
 }
Exemplo n.º 8
0
 private void ReduceEvent(LALRParser parser, ReduceEventArgs args)
 {
     try
     {
         args.Token.UserObject = CreateObject(args.Token);
     }
     catch (Exception e)
     {
         args.Continue = false;
         MainForm.mainForm.WriteResult(e.Message);
     }
 }
Exemplo n.º 9
0
        private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
        {
            /*** MODIFICAÇÕES ***/
            String file_name         = _mainForm.getFileName();
            String error_type        = "Lexical error";
            String line_number       = args.Token.Location.LineNr.ToString();
            String col_number        = args.Token.Location.ColumnNr.ToString();
            String error_description = "Unrecognized symbol at .. " + args.Token.ToString();

            _insertError(file_name, error_type, line_number, col_number, error_description);
            /*** MODIFICAÇÕES ***/
        }
Exemplo n.º 10
0
        private void TokenReadEvent(LALRParser parser, TokenReadEventArgs args)
        {
            args.Token.UserObject = CreateObject(args.Token);

            int tmp = args.Token.Symbol.Id;

            string lexem = args.Token.ToString();
            string token = ((SymbolConstants)args.Token.Symbol.Id).ToString().Substring(7);

            //string token = args.Token.Symbol.Name.ToString();
            dt.Rows.Add(lexem, token);
        }
Exemplo n.º 11
0
 private void AcceptEvent(LALRParser parser, AcceptEventArgs args)
 {
     MainForm.mainForm.ClearShowInputError();
     try
     {
         Expression exp = (Expression)args.Token.UserObject;
         MainForm.mainForm.WriteResult(exp.Evaluate().ToString());
     }
     catch (Exception e)
     {
         MainForm.mainForm.WriteResult(e.Message);
     }
 }
Exemplo n.º 12
0
        private void Init(Stream stream)
        {
            numberFormatInfo = new NumberFormatInfo();
            numberFormatInfo.NumberDecimalSeparator = ".";
            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);
        }
Exemplo n.º 13
0
        private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
        {
            string ExpectedTokens = "Expected Token : '" + args.ExpectedTokens.ToString() + "'";

            errors.Items.Add(ExpectedTokens);

            string UnexpectedToken = "Wrong Token : '" + args.UnexpectedToken.ToString() + "'";

            errors.Items.Add(UnexpectedToken);

            string errorLine = "Error Near By Line : " + args.UnexpectedToken.Location.LineNr;

            errors.Items.Add(errorLine);
            //todo: Report message to UI?
        }
Exemplo n.º 14
0
 private void ReduceEvent(LALRParser parser, ReduceEventArgs args)
 {
     try
     {
         args.Token.UserObject = CreateObject(args.Token);
     }
     catch (Exception e)
     {
         _mainForm.setLeituraState(false);
         _mainForm.setSyntaxState(false);
         MessageBox.Show(e.ToString());
         args.Continue = false;
         //todo: Report message to UI?
     }
 }
Exemplo n.º 15
0
        private void TokenReadEvent(LALRParser parser, TokenReadEventArgs args)
        {
            SymbolConstants symb;

            for (symb = 0; (int)symb < 68; symb++)
            {
                if ((int)symb == args.Token.Symbol.Id && (int)symb != 0)
                {
                    ListViewItem lst = new ListViewItem();
                    lst.SubItems.Add(args.Token.Text);
                    lst.SubItems.Add(symb.ToString());
                    lstlex.Items.Add(lst);
                    break;
                }
            }
        }
Exemplo n.º 16
0
        private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
        {
            /*** MODIFICAÇÕES ***/
            String file_name         = _mainForm.getFileName();
            String error_type        = "Syntax error";
            String line_number       = args.UnexpectedToken.Location.LineNr.ToString();
            String col_number        = args.UnexpectedToken.Location.ColumnNr.ToString();
            String error_description = "Error at .. " + args.UnexpectedToken.ToString();

            String unexpectedToken = args.UnexpectedToken.ToString();
            String expectedTokens  = args.ExpectedTokens.ToString();

            String[] aExpectedTokens = expectedTokens.Split(' ');
            String   nextToken       = aExpectedTokens[0];

            int token_id = 0;

            foreach (SymbolConstants symbol in (Enum.GetValues(typeof(SymbolConstants))))
            {
                String symbol_token = symbol.ToString()
                                      .Replace("SYMBOL_", "")
                                      .ToLower();

                if (symbol_token == nextToken)
                {
                    token_id = (int)symbol;
                    break;
                }
            }

            _insertError(file_name, error_type, line_number, col_number, error_description);

            Location location = new Location(0, 0, 0);

            args.NextToken = new TerminalToken(new SymbolTerminal(token_id, nextToken), "", location);
            args.Continue  = ContinueMode.Insert;
            /*** MODIFICAÇÕES ***/
        }
Exemplo n.º 17
0
        private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
        {
            Context.ExpectedTokens = args.ExpectedTokens.ToString();
            if(args.NextToken!=null)
            Context.NextToken = args.NextToken.ToString();
            if (args.UnexpectedToken != null)
            Context.UnexpectedToken = args.UnexpectedToken.ToString();

            throw new ParseException(args);
        }
Exemplo n.º 18
0
 private void TokenReadEvent(LALRParser parser, TokenReadEventArgs args)
 {
     try
     {
         args.Token.UserObject = CreateObject(args.Token);
     }
     catch (Exception e)
     {
         args.Continue = false;
         Console.WriteLine(args.Token.ToString());
         //todo: Report message to UI?
     }
 }
Exemplo n.º 19
0
 private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
 {
     string message = "Parse error caused by token: '"+args.UnexpectedToken.ToString()+"'";
     //todo: Report message to UI?
 }
Exemplo n.º 20
0
 private void AcceptEvent(LALRParser parser, AcceptEventArgs args)
 {
     //todo: Use your fully reduced args.Token.UserObject
 }
Exemplo n.º 21
0
 private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
 {
     throw new TokenException(args);
 }
Exemplo n.º 22
0
 private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
 {
     throw new ParseException(args);
 }
Exemplo n.º 23
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);
         }
     }
 }
Exemplo n.º 24
0
        protected virtual void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
        {
			string message = String.Format("Token error with input: '{0}' at location {1}", args.Token, args.Token.Location);
			throw new ParserException(message);
        }
Exemplo n.º 25
0
 private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
 {
     message = message + "Parse error caused by token: " + args.UnexpectedToken.ToString() + "\n" + "in line : " + args.UnexpectedToken.Location.LineNr + "\n";
     //todo: Report message to UI?
     message = message + "expected token : " + args.ExpectedTokens.ToString() + "\n";
 }
Exemplo n.º 26
0
        private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
        {
            AddViewItem("Parse error", null, "Expecting the following tokens:",
                args.ExpectedTokens.ToString(),"",5);
            errors++;

            if (errors <= maxerrors)
            {
                args.Continue = ContinueMode.Skip;
                // example for inserting a new token
                /*
                args.Continue = ContinueMode.Insert;
                TerminalToken token = new TerminalToken((SymbolTerminal)parser.Symbols.Get(4),
                                                        "555",
                                                        new Location(0, 0, 0));
                args.NextToken = token;
                */
            }
        }
Exemplo n.º 27
0
 private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
 {
     message = message + "Token error with input: '" + args.Token.ToString() + "'";
     //todo: Report message to UI?
 }
Exemplo n.º 28
0
 /// <summary>
 /// Event handler for the action of reading a token.
 /// </summary>
 /// <param name="parser">parser that is the source of this event</param>
 /// <param name="args">event arguments</param>
 private void TokenReadEvent(LALRParser parser, TokenReadEventArgs args)
 {
     AddViewItem("Token Read",
         args.Token.Location,
         args.Token.Symbol.ToString(),
         StringUtil.ShowEscapeChars(args.Token.Text),"",0);
 }
Exemplo n.º 29
0
 private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
 {
     AddViewItem("Token error", args.Token.Location, "Cannot recognize token",
         args.Token.Text,"",5);
     errors++;
     if (errors <= maxerrors)
         args.Continue = true;
 }
Exemplo n.º 30
0
 private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
 {
     MainForm.mainForm.ShowInputError(args.UnexpectedToken);
     MainForm.mainForm.WriteResult("Parse error caused by token: '" + args.UnexpectedToken.ToString() + "'");
 }
Exemplo n.º 31
0
        protected virtual void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
        {
			string message = String.Format("Parse error caused by token: '{0}' at location {1}", args.UnexpectedToken, args.UnexpectedToken.Location);
			throw new ParserException(message);
        }
Exemplo n.º 32
0
 private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
 {
     string message = "Parse error caused by token: '" + args.UnexpectedToken.ToString() + "'";
     //todo: Report message to UI?
 }
Exemplo n.º 33
0
 private void ReduceEvent(LALRParser parser, ReduceEventArgs args)
 {
     try
     {
         args.Token.UserObject = CreateObject(args.Token);
     }
     catch (Exception e)
     {
         args.Continue = false;
         //todo: Report message to UI?
     }
 }
Exemplo n.º 34
0
 /// <summary>
 /// Event handler for the shift action.
 /// </summary>
 /// <param name="parser">parser that is the source of this event</param>
 /// <param name="args">event arguments</param>
 private void ShiftEvent(LALRParser parser, ShiftEventArgs args)
 {
     AddViewItem("Shift",
         args.Token.Location,
         args.Token.Symbol.ToString(),
         StringUtil.ShowEscapeChars(args.Token.Text),
         args.NewState.Id.ToString(),
         1);
 }
Exemplo n.º 35
0
 /// <summary>
 /// Event handler for the reading a comment.
 /// </summary>
 /// <param name="parser">parser that is the source of this event</param>
 /// <param name="args">event arguments</param>
 private void CommentReadEvent(LALRParser parser, CommentReadEventArgs args)
 {
     string desc;
     if (args.LineComment)
         desc = "Line Comment";
     else
         desc = "Block Comment";
     AddViewItem("Comment Read", null, desc, args.Content, "", 6);
 }
Exemplo n.º 36
0
 private void ReduceEvent(LALRParser parser, ReduceEventArgs args)
 {
     try
     {
         args.Token.UserObject = CreateObject(args.Token);
     }
     catch (ApplicationException ex)
     {
         args.Continue = false;
         Logger.Log(DateTime.Now + ":  " + ex.Message);
         //todo: Report message to UI?
     }
 }
Exemplo n.º 37
0
        private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
        {   
            
			string message = args.UnexpectedToken.Location.ToString()+"[\n\r"; 
			message+="Unexpected Token: '"+args.UnexpectedToken.ToString()+"'\n\rExpected: '"+args.ExpectedTokens.ToString()+"'";
            if (LastGotoEventArgs!=null) message+="\n\rLastGoto:"+LastGotoEventArgs.Symbol.ToString();
			if (LastReduceEventArgs!=null) message+="\n\rLastReduce.Rule:"+LastReduceEventArgs.Rule.ToString();			
			message+="\n\r]";
			Console.WriteLine(message);
        }                
Exemplo n.º 38
0
 private void TokenReadEvent(LALRParser parser, TokenReadEventArgs args)
 {
     try
     {
         args.Token.UserObject = CreateObject(args.Token);
     }
     catch (ApplicationException ex)
     {
         args.Continue = false;
         tokenStack.Clear();
         Logger.Log(DateTime.Now + ":  " + ex.Message);
         throw ex;
     }
 }
Exemplo n.º 39
0
 private void TokenReadEvent(LALRParser parser, TokenReadEventArgs Args)
 {
     Args.Token.UserObject = CreateObject(Args.Token);
     Label1.Text          += Args.Token.Text + " ==> " + ((SymbolConstants)Args.Token.Symbol.Id) + "\n";
 }
Exemplo n.º 40
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);
        }
Exemplo n.º 41
0
 private void AcceptEvent(LALRParser parser, AcceptEventArgs args)
 {
     AddViewItem("Accept",null,"","","",4);
     FillTreeView(parseTreeView,args.Token);
     tabControl.SelectedIndex = 2;
 }
Exemplo n.º 42
0
 private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
 {
     string message = "Token error with input: '"+args.Token.ToString()+"'";
     //todo: Report message to UI?
 }
Exemplo n.º 43
0
 private void AcceptEvent(LALRParser parser, AcceptEventArgs args)
 {
     //todo: Use your fully reduced args.Token.UserObject
 }
Exemplo n.º 44
0
 /// <summary>
 /// Event handlers for the goto action.
 /// </summary>
 /// <param name="parser">parser that is the source of this event</param>
 /// <param name="args">parser that is the source of this event</param>
 public void GotoEvent(LALRParser parser, GotoEventArgs args)
 {
     AddViewItem("Goto",
         null,
         args.Symbol.ToString(),
         "",
         args.NewState.Id.ToString(),
         3);
 }
Exemplo n.º 45
0
 void parser_OnAccept(LALRParser parser, AcceptEventArgs args)
 {
     //try
        //{
        //    generateCmdHasTable();
        Enabled = true;
       // Console.WriteLine("Parser Success!");
        //}
        //catch (Exception ex)
        //{
        //    Console.WriteLine("On_accept:" + ex.Message);
        //}
 }
Exemplo n.º 46
0
 private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
 {
     MainForm.mainForm.ShowInputError(args.Token);
     MainForm.mainForm.WriteResult("Token error with input: '" + args.Token.ToString() + "'");
 }
Exemplo n.º 47
0
 private void parser_OnParseError(LALRParser parser, ParseErrorEventArgs args)
 {
     string message;
        message=args.UnexpectedToken.Location+",unexpect token:"+args.UnexpectedToken.Text;
        throw new Exception(message);
 }
Exemplo n.º 48
0
        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)
            {
                RuleContext = new Rule_Context();
            }
            else
            {
                RuleContext = new Rule_Context(pScope);
            }
        }
Exemplo n.º 49
0
        private void AcceptEvent(LALRParser parser, AcceptEventArgs args)
        {
            NonterminalToken T = (NonterminalToken)args.Token;
            mContext.AnalysisCheckCodeInterface = this.AnalysisCheckCodeInterface;
            this.Context.AnalysisInterpreterHost = this;
            AnalysisRule program = AnalysisRule.BuildStatments(mContext, T);

            if (this.IsExecuteMode)
            {
                program.Execute();
            }

            this.ProgramStart = null;
        }
Exemplo n.º 50
0
        private void AcceptEvent(LALRParser parser, AcceptEventArgs args)
        {
            NonterminalToken nonterminalToken = (NonterminalToken)args.Token;

            RuleContext.EnterCheckCodeInterface = this.EnterCheckCodeInterface;

            RuleContext.ClearState();
            EnterRule program = EnterRule.BuildStatments(RuleContext, nonterminalToken);

            program.Execute();

            RuleContext.CheckAssignedVariables();
        }
Exemplo n.º 51
0
        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));
        }
Exemplo n.º 52
0
        private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
        {
            string message = args.Token.Location.ToString()+"[\n\r";
			message+="Token error with input: '"+args.Token.ToString()+"'";
			if (LastGotoEventArgs!=null) message+="\n\rLastGoto:"+LastGotoEventArgs.Symbol.ToString();
			if (LastReduceEventArgs!=null) message+="\n\rLastReduce.Rule:"+LastReduceEventArgs.Rule.ToString();			            
			message+="\n\r]";
			Console.WriteLine(message);
        }
Exemplo n.º 53
0
 /// <summary>
 /// Event handler for the reduce action.
 /// </summary>
 /// <param name="parser">parser that is the source of this event</param>
 /// <param name="args">event arguments</param>
 private void ReduceEvent(LALRParser parser, ReduceEventArgs args)
 {
     //WriteLn(args.Rule.Id.ToString());
     //WriteLn(args.Rule.Lhs.Id.ToString());
     AddViewItem("Reduce",
         null,
         args.Token.Rule.ToString(),
         "",
         args.NewState.Id.ToString(),
         2);
 }