public void AddEntryPoint(Gramatica gramatica)
        {
            CodeEntryPointMethod  start       = new CodeEntryPointMethod();
            CodeSnippetExpression methodValue = new CodeSnippetExpression();

            methodValue.Value += "stringIndex = 0;\n" +
                                 $" inputArrayString = Console.ReadLine().Split(\' \'); \n" +
                                 "try \n" +
                                 "{\n" +
                                 $"\t { gramatica.Start } (); \n" +
                                 "if( inputArrayString[stringIndex] == \"$\" ) \n" +
                                 "\tConsole.WriteLine(\"Propozitie corecta\");\n" +
                                 "else\n" +
                                 "Console.WriteLine(\"Propozitie Incorecta\");\n" +
                                 "}\n" +
                                 "catch(Exception e)\n" +
                                 "{\n" +
                                 "Console.WriteLine(e.Message);\n" +
                                 "Console.WriteLine(\"Propozitie Incorecta\");\n" +
                                 "}\n" +
                                 "Console.ReadKey();\n"
            ;
            start.Statements.Add(new CodeSnippetStatement(methodValue.Value));
            targetClass.Members.Add(start);
        }
        public void AddMethods(Gramatica gramatica)
        {
            List <CodeMemberMethod> methodList = new List <CodeMemberMethod>();

            for (int i = 0; i < gramatica.Neterminale.Count; i++)
            {
                CodeMemberMethod tmp = new CodeMemberMethod
                {
                    Attributes = MemberAttributes.Private | MemberAttributes.Static,
                    Name       = gramatica.Tab.Rows[i][0].ToString(),
                    ReturnType = new CodeTypeReference(typeof(void)),
                };
                targetClass.Members.Add(tmp);
                CodeSnippetExpression methodValue = new CodeSnippetExpression();
                for (int j = 1; j <= gramatica.Terminale.Count + 1; j++)
                {
                    ReguliDeProductie regula = gramatica.Tab.Rows[i][j] as ReguliDeProductie;
                    if (regula != null)
                    {
                        methodValue.Value += $"if( inputArrayString[stringIndex] == \"{gramatica.Tab.Columns[j].Caption}\" )\n" +
                                             "{\n";

                        if (regula.GetRight().Count() >= 1 && regula.GetRight()[0] != "")
                        {
                            foreach (var symbol in regula.GetRight())
                            {
                                if (gramatica.Neterminale.Contains(symbol))
                                {
                                    methodValue.Value += $"{symbol}();\n";
                                }
                                if (gramatica.Terminale.Contains(symbol))
                                {
                                    methodValue.Value += "stringIndex++;\n";
                                }
                            }
                        }
                        methodValue.Value += "return;\n";

                        methodValue.Value += "}\n";
                    }
                }

                methodValue.Value += $"else\nthrow new Exception($\"Caracter invalid la pozitia {{ stringIndex }}\");\n";
                tmp.Statements.Add(new CodeSnippetStatement(methodValue.Value));
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            Gramatica x = new Gramatica();

            x.GetData(@"D:\input.txt");
            // x.PrintNrReguli();
            x.PrintReguliProductie();
            Console.WriteLine("\n\n\n");
            x.EliminareReguliIdentice();


            //x.PrintNeterminale();
            // x.PrintTerminale();
            // x.PrintNrReguli();
            // Console.WriteLine();
            //x.PrintReguliProductie();
            // Console.WriteLine();
            // Console.WriteLine();

            x.EliminareRecursivitateStanga();

            //Console.WriteLine("\n\n\n");
            x.PrintReguliProductie();

            x.PrintNrReguli();
            x.PrintNeterminale();
            Console.WriteLine("\n\n\n");
            x.MultimeSimboliDirectori();
            x.PrintSimboliDirectori();
            x.MultimiDisjuncte();
            x.TabelaDeAnalizaSintactica();
            x.PopulareTabela();


            CodeGenerator codeGenerator = new CodeGenerator();

            codeGenerator.AddEntryPoint(x);
            codeGenerator.AddFields();
            codeGenerator.AddMethods(x);
            codeGenerator.GenerateCSharpCode("output.cs");
            //x.PrintNrReguli();
        }