Пример #1
0
        public void Syntactic_Analysis()
        {
            //Save the data the section SETS if exist
            if (L_Sets != null)
            {
                foreach (var item in L_Sets)
                {
                    N_Sets.Add(Name_SETS(item));
                }
            }

            //Create ER for syntactic analysis
            //instance class for functions the ER
            ER     FER         = new ER();
            string ER_analysis = "";              //Save here ER for syntactic analysis

            ER_analysis = FER.CreateER(L_Tokens); //SAVE ER version 1
            string flag_SETS = FER.Is_Correct_SETS(ER_analysis, N_Sets);

            if (flag_SETS == "GG")
            {
                ER_analysis   = FER.String_Completed(ER_analysis); //completed string with symbol '.'
                textBox2.Text = ER_analysis;                       //show user

                //create tree
                ETree        T_Tokens    = new ETree();
                Stack <Nodo> Tree_Tokens = new Stack <Nodo>(); //stack the final tree
                Tree_Tokens = T_Tokens.Insert(ER_analysis);    //get tree
                // SECOND PHASE AFD the ETree
                //insert values the first , last and follow for direct method AFD
                AFD  afd        = new AFD(); //instance class
                Nodo Node_Token = new Nodo();
                Node_Token = afd.Direct_Method(Tree_Tokens.Pop());

                //Third Phase Transitions the AFD the Etree

                Columns_Transitions = afd.Transitions_Insert(Columns_Transitions, Node_Token); //save name the columns
                Values_Transitions  = afd.Transitions_values(Values_Transitions, Node_Token, Columns_Transitions, Status);
                Status             = afd.FixList(Status);                                      //order number
                Values_Transitions = afd.FixList2(Values_Transitions);
                //Method for show in DataGridView
                Show_FirstLast(Node_Token);                                        //show in data grid view data the first and last
                Show_Follow(Node_Token);                                           // show in data grid view data the follow
                Show_Transitions(Columns_Transitions, Status, Values_Transitions); //shoq in data grid view data the transitions

                //Me servira para la fase 3
                GetLastFollow(Node_Token);

                //show tree in image
                //string ruta = T_Tokens.graphic(Node_Token);

                //System.Threading.Thread.Sleep(1000);

                //FileStream file = new FileStream(ruta, FileMode.Open);
                //Image img = Image.FromStream(file);
                //pictureBox1.Image = img;
                //file.Close();
            }
            else
            {
                MessageBox.Show(flag_SETS); //END PROGRAM
            }
        }
Пример #2
0
        //---------------------------------------------FUNCTIONS PUBLIC----------------------------------------------

        //o --> error      1 --> correcto

        //method to do semantic analysis
        public int Semantic_Analysis()
        {
            //instance class
            ReadFileC rf = new ReadFileC();

            //return config start
            button2.Enabled  = false;
            textBox1.Enabled = false;

            //get data from the all file
            string[] res = rf.ReadFile(PathFile);

            if (res.Length == 0)
            {
                MessageBox.Show("El archivo se encontro vacio."); //end program
                return(0);
            }
            else
            {
                //add items at lists
                L_Sets    = rf.SplitSets(res);        //tested
                L_Tokens  = rf.SplitTokens(res);      //tested
                L_Actions = rf.SplitActions(res);     //tested
                L_Error   = rf.SplitError(res);       //tested
                L_Actions = rf.FixActions(L_Actions); //testeed
                //firs filter (key words)
                if (F_KeyWords(L_Tokens, L_Actions, L_Error) != "GG")
                {
                    MessageBox.Show(F_KeyWords(L_Tokens, L_Actions, L_Error)); //end program
                    return(0);
                }
                else
                {
                    MessageBox.Show("Primer Filtro Correcto"); //CONTINUED
                                                               //------------------- SECOND FILTER

                    //Create string ER
                    string ER_sets1   = "(a+.f+.g.(f+.h.(a|b|c|i).h.(j|k)?)+).#";                   //LETRA   = 'A'..'Z'+'a'..'z'+'_'
                    string ER_sets2   = "(a+.f+.g.(f+.d+.l.c+.m.j?)+).#";                           //CHARSET = CHR(32)..CHR(254)
                    string ER_tokens  = "(e+.f+.c+.f*.g.f*.((h.(a|i).h)*|(a|f|n)*|(a|b|f|i)*)+).#"; //'"' CHARSET '"'|''' CHARSET ''' // LETRA ( LETRA | DIGITO )*   { RESERVADAS() }
                    string ER_actions = "(c+.f.g.f.h.a+.h).#";                                      //18 = 'PROGRAM'
                    string ER_error   = "(ñ+.f.g.f.c+).#";                                          //ERROR = 54

                    //Create tree for each ER...
                    ETree T_Sets    = new ETree();
                    ETree T_Sets2   = new ETree();
                    ETree T_Tokens  = new ETree();
                    ETree T_Actions = new ETree();
                    ETree T_Error   = new ETree();

                    //Create stack for each ER
                    Stack <Nodo> Tree_Sets    = new Stack <Nodo>();
                    Stack <Nodo> Tree_Sets2   = new Stack <Nodo>();
                    Stack <Nodo> Tree_Tokens  = new Stack <Nodo>();
                    Stack <Nodo> Tree_Actions = new Stack <Nodo>();
                    Stack <Nodo> Tree_Error   = new Stack <Nodo>();

                    //Insert value in differents trees
                    Tree_Sets    = T_Sets.Insert(ER_sets1);
                    Tree_Sets2   = T_Sets2.Insert(ER_sets2);
                    Tree_Tokens  = T_Tokens.Insert(ER_tokens);
                    Tree_Actions = T_Actions.Insert(ER_actions);
                    Tree_Error   = T_Error.Insert(ER_error);

                    // recorrido
                    T_Sets.InOrder(Tree_Sets.Pop());
                    T_Sets2.InOrder(Tree_Sets2.Pop());
                    T_Tokens.InOrder(Tree_Tokens.Pop());
                    T_Actions.InOrder(Tree_Actions.Pop());
                    T_Error.InOrder(Tree_Error.Pop());

                    //mostrar recorrido de arboles
                    //MessageBox.Show(T_Sets.cadena);
                    //MessageBox.Show(T_Sets2.cadena);
                    //MessageBox.Show(T_Tokens.cadena);
                    //MessageBox.Show(T_Actions.cadena);
                    //MessageBox.Show(T_Error.cadena);

                    //----------------------------- READ SECTIONS -----------------------------------------------

                    //send all tokens
                    Token        t   = new Token();
                    List <Token> L_t = new List <Token>();
                    L_t = t.Insert_Tokens();

                    //filter sets
                    if (rf.ReadSets(L_Sets, L_t, ER_sets1, ER_sets2) != "GG")
                    {
                        string er      = rf.ReadSets(L_Sets, L_t, ER_sets1, ER_sets2);
                        char[] x       = er.ToArray();
                        int    columna = Error_Columna(x);
                        int    line    = Error_Line(x, res);
                        MessageBox.Show(er);
                        MessageBox.Show("Error en la linea: " + line + " Columna: " + columna);
                        return(0);
                    }
                    //filter tokens
                    else if (rf.ReadTokens(L_Tokens, L_t, ER_tokens) != "GG")
                    {
                        string er      = rf.ReadTokens(L_Tokens, L_t, ER_tokens);
                        char[] x       = er.ToArray();
                        int    columna = Error_Columna(x);
                        int    line    = Error_Line(x, res);
                        MessageBox.Show(er);
                        MessageBox.Show("Error en la linea: " + line + " Columna: " + columna);
                        return(0);
                    }
                    //filter action
                    else if (rf.ReadAction(L_Actions, L_t, ER_actions) != "GG")
                    {
                        string er      = rf.ReadAction(L_Actions, L_t, ER_actions);
                        char[] x       = er.ToArray();
                        int    columna = Error_Columna(x);
                        int    line    = Error_Line_A(x, res);
                        if (line == 0)
                        {
                            line = Error_Line(x, res);
                        }
                        MessageBox.Show(er);
                        MessageBox.Show("Error en la linea: " + line + " Columna: " + columna);
                        return(0);
                    }
                    //filter error
                    else if (rf.ReadError(L_Error, L_t, ER_error) != "GG")
                    {
                        string er      = rf.ReadError(L_Error, L_t, ER_error);
                        char[] x       = er.ToArray();
                        int    columna = Error_Columna(x);
                        int    line    = Error_Line(x, res);
                        MessageBox.Show(er);
                        MessageBox.Show("Error en la linea: " + line + " Columna: " + columna);
                        return(0);
                    }
                    else
                    {
                        MessageBox.Show("Archivo leido correctamente :)");
                        return(1);
                    }
                }
            } //fiter the file empity
        }