示例#1
0
文件: Loader.cs 项目: sebgod/hime
        /// <summary>
        /// Parses the input with the given identifier
        /// </summary>
        /// <param name="name">The input's name</param>
        /// <param name="reader">The input's reader</param>
        /// <returns><c>true</c> if the operation succeed</returns>
        private bool LoadInput(string name, TextReader reader)
        {
            reporter.Info("Reading input " + name + " ...");
            bool              hasErrors = false;
            HimeGrammarLexer  lexer     = new HimeGrammarLexer(reader);
            HimeGrammarParser parser    = new HimeGrammarParser(lexer);
            ParseResult       result    = null;

            try
            {
                result = parser.Parse();
            }
            catch (System.Exception ex)
            {
                reporter.Error("Fatal error in " + name);
                reporter.Error(ex);
                hasErrors = true;
            }
            foreach (ParseError error in result.Errors)
            {
                reporter.Error(name + error.Message, result.Input, error.Position);
                hasErrors = true;
            }
            if (result.IsSuccess)
            {
                foreach (ASTNode gnode in result.Root.Children)
                {
                    Grammars.Loader loader = new Grammars.Loader(name, result.Input, gnode, reporter);
                    inners.Add(loader.Grammar.Name, loader);
                }
            }
            reader.Close();
            return(!hasErrors);
        }
示例#2
0
文件: Loader.cs 项目: sebgod/hime
        /// <summary>
        /// Solves the dependencies between the inputs and interprets the parsed inputs
        /// </summary>
        /// <returns><c>true</c> if all dependencies were solved</returns>
        private bool SolveDependencies()
        {
            int unsolved = 1;

            while (unsolved != 0)
            {
                unsolved = 0;
                int solved = 0;
                foreach (Grammars.Loader loader in inners.Values)
                {
                    if (loader.IsSolved)
                    {
                        continue;
                    }
                    loader.Load(inners);
                    if (loader.IsSolved)
                    {
                        solved++;
                    }
                    else
                    {
                        unsolved++;
                    }
                }
                if (unsolved != 0 && solved == 0)
                {
                    foreach (string name in inners.Keys)
                    {
                        Grammars.Loader loader = inners[name];
                        foreach (string dep in loader.Dependencies)
                        {
                            reporter.Error(string.Format("Failed to solve dependency of {0} on {1}", name, dep));
                        }
                    }
                    return(false);
                }
            }
            return(true);
        }
示例#3
0
文件: Loader.cs 项目: sebgod/hime
 /// <summary>
 /// Loads the specified input
 /// </summary>
 /// <param name="node">The parse tree of a grammar</param>
 /// <param name="input">The input that contains the grammar</param>
 /// <returns><c>true</c> if the operation succeed</returns>
 private bool LoadInput(ASTNode node, Text input)
 {
     Grammars.Loader loader = new Grammars.Loader(node.Children[0].Value, input, node, reporter);
     inners.Add(loader.Grammar.Name, loader);
     return(true);
 }