コード例 #1
0
        public virtual void GenerateATNs(Grammar g)
        {
            DOTGenerator    dotGenerator = new DOTGenerator(g);
            IList <Grammar> grammars     = new List <Grammar>();

            grammars.Add(g);
            IList <Grammar> imported = g.GetAllImportedGrammars();

            if (imported != null)
            {
                foreach (Grammar importedGrammar in imported)
                {
                    grammars.Add(importedGrammar);
                }
            }

            foreach (Grammar ig in grammars)
            {
                foreach (Rule r in ig.rules.Values)
                {
                    try
                    {
                        string dot = dotGenerator.GetDOT(g.atn.ruleToStartState[r.index], g.IsLexer());
                        if (dot != null)
                        {
                            WriteDOTFile(g, r, dot);
                        }
                    }
                    catch (IOException ioe)
                    {
                        errMgr.ToolError(ErrorType.CANNOT_WRITE_FILE, ioe);
                    }
                }
            }
        }
コード例 #2
0
        void checkRuleATN(Grammar g, string ruleName, string expecting)
        {
            ParserATNFactory f = new ParserATNFactory(g);
            ATN atn            = f.createATN();

            DOTGenerator dot = new DOTGenerator(g);

            Console.WriteLine(dot.getDOT(atn.ruleToStartState[g.getRule(ruleName).index]));

            Rule       r          = g.getRule(ruleName);
            ATNState   startState = atn.ruleToStartState[r.index];
            ATNPrinter serializer = new ATNPrinter(g, startState);
            string     result     = serializer.asstring();

            //System.out.print(result);
            assertEquals(expecting, result);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            //            try {
            CmdLineParser cmdLineParser = new CmdLineParser("FSMCompiler v1.0");

            cmdLineParser.Add(new ArgumentDefinition("source", 1, "Archivo de entrada.", true));
            cmdLineParser.Add(new OptionDefinition("G", "Generador."));
            cmdLineParser.Add(new OptionDefinition("H", "Ayuda."));
            cmdLineParser.Add(new OptionDefinition("P", "Parametro especifico del generador."));

            if (args.Length == 0)
            {
                Console.WriteLine(cmdLineParser.HelpText);
                Console.ReadKey(true);
            }

            else
            {
                string generatorName  = "C";
                string sourceFileName = "";
                GeneratorParameters generatorParameters = new GeneratorParameters();

                cmdLineParser.Parse(args);
                foreach (OptionInfo optionInfo in cmdLineParser.Options)
                {
                    switch (optionInfo.Name)
                    {
                    case "G":
                        generatorName = optionInfo.Value;
                        break;

                    case "P":
                        generatorParameters.Add(optionInfo.Value);
                        break;
                    }
                }
                foreach (ArgumentInfo argumentInfo in cmdLineParser.Arguments)
                {
                    switch (argumentInfo.Name)
                    {
                    case "source":
                        sourceFileName = argumentInfo.Value;
                        break;
                    }
                }

                Console.WriteLine();
                Console.WriteLine("FsmCompiler v1.1");
                Console.WriteLine("-------------------------------------------------------------");
                Console.WriteLine("  Finite state machine compiler tool.");
                Console.WriteLine("  Copyright 2015-2020 Rafael Serrano ([email protected])");
                Console.WriteLine();

                XmlLoader loader  = new XmlLoader();
                Machine   machine = loader.Load(sourceFileName);

                IGenerator generator = null;
                switch (generatorName)
                {
                case "DOT":
                    generator = new DOTGenerator(generatorParameters);
                    break;

                case "C":
                default:
                    generator = new CGenerator(generatorParameters);
                    break;

                case "CPP":
                    generator = new v1.Generator.CPP.CPPGenerator(generatorParameters);
                    break;
                }

                generator.Generate(machine);
            }

            /*          }
             *
             *        catch (Exception e) {
             *            while (e != null) {
             *                Console.WriteLine(e.Message);
             *                e = e.InnerException;
             *            }
             *        }*/
        }