예제 #1
0
        /**
         * ruleForJSGF
         */
        public static JSGFRule RuleForJSGF(String text)
        {
            JSGFRule r = null;

            try
            {
                StringReader sread = new StringReader(text);
                if (_parser == null)
                {
                    _parser = new JSGFParser(sread);
                }
                else
                {
                    _parser.ReInit(sread);
                }
                r = _parser.Alternatives();
                // Console.WriteLine("JSGF Parser Version " + version
                //                    + ":  JSGF RHS parsed successfully.");
            }
            catch (ParseException e)
            {
                Console.WriteLine("JSGF Parser Version " + Version + ":  Encountered errors during parse.");
            }
            return(r);
        }
예제 #2
0
        /**
         * newGrammarFromJSGF - Once JavaCC supports Readers we will change this
         */
        public static JSGFRuleGrammar NewGrammarFromJSGF(Stream i, JSGFRuleGrammarFactory factory)
        {
            JSGFRuleGrammar grammar = null;

            if (_parser == null)
            {
                _parser = new JSGFParser(i);
            }
            else
            {
                _parser.ReInit(i);
            }
            try
            {
                grammar = _parser.GrammarUnit(factory);
                return(grammar);
            }
            catch (ParseException e)
            {
                Token etoken = e.CurrentToken;
                JSGFGrammarParseException ge = new JSGFGrammarParseException(etoken.BeginLine, etoken.BeginColumn, "Grammar Error", e.Message);
                throw ge;
            }
        }
예제 #3
0
 // This main method simply checks the syntax of a jsgf Grammar
 //
 public static void Main(String[] args)
 {
     if (args.Length == 0)
     {
         Console.WriteLine("JSGF Parser Version " + Version + ":  Reading from standard input . . .");
         _parser = new JSGFParser(Console.In);
     }
     else if (args.Length > 0)
     {
         Console.WriteLine("JSGF Parser Version " + Version + ":  Reading from file " + args[0] + " . . .");
         try
         {
             FileInfo codeBase = null;
             String   path     = Directory.GetCurrentDirectory() + "/" + args[0];
             try
             {
                 codeBase = new FileInfo(path);
             }
             catch (UriFormatException e)
             {
                 Console.WriteLine("Could not get URL for current directory " + e);
                 return;
             }
             BufferedStream i        = new BufferedStream(codeBase.OpenRead(), 256);
             JSGFEncoding   encoding = GetJSGFEncoding(i);
             TextReader     rdr;
             if ((encoding != null) && (encoding.Encoding != null))
             {
                 Console.WriteLine("Grammar Character Encoding \"" + encoding.Encoding + "\"");
                 rdr = new StreamReader(i, encoding.GetEncoding);
             }
             else
             {
                 if (encoding == null)
                 {
                     Console.WriteLine("WARNING: Grammar missing self identifying header");
                 }
                 rdr = new StreamReader(i);
             }
             _parser = new JSGFParser(rdr);
         }
         catch (Exception e)
         {
             Console.WriteLine("JSGF Parser Version " + Version + ":  File " + args[0] + " not found.");
             return;
         }
     }
     else
     {
         Console.WriteLine("JSGF Parser Version " + Version + ":  Usage is one of:");
         Console.WriteLine("         java JSGFParser < inputfile");
         Console.WriteLine("OR");
         Console.WriteLine("         java JSGFParser inputfile");
         return;
     }
     try
     {
         _parser.GrammarUnit(new JSGFRuleGrammarFactory(new JSGFRuleGrammarManager()));
         Console.WriteLine("JSGF Parser Version " + Version + ":  JSGF Grammar parsed successfully.");
     }
     catch (ParseException e)
     {
         Console.WriteLine("JSGF Parser Version " + Version + ":  Encountered errors during parse." + e.Message);
     }
 }