示例#1
0
文件: Loader.cs 项目: sebgod/hime
        /// <summary>
        /// Builds the set of rule definitions that represents a single virtual symbol
        /// </summary>
        /// <param name="node">The AST node of a syntactic rule</param>
        /// <returns>The set of possible rule definitions</returns>
        private RuleBodySet BuildAtomicVirtual(ASTNode node)
        {
            RuleBodySet set  = new RuleBodySet();
            string      name = node.Children[0].Value;

            name = ReplaceEscapees(name.Substring(1, name.Length - 2));
            Virtual vir = grammar.GetVirtual(name) ?? grammar.AddVirtual(name);

            set.Add(new RuleBody(vir));
            return(set);
        }
示例#2
0
        /// <summary>
        /// Adds a virtual symbol with the given name to this grammar
        /// </summary>
        /// <param name="name">The virtual's name</param>
        /// <returns>The new virtual</returns>
        public Virtual AddVirtual(string name)
        {
            if (virtuals.ContainsKey(name))
            {
                return(virtuals[name]);
            }
            Virtual symbol = new Virtual(nextSID, name);

            nextSID++;
            virtuals.Add(name, symbol);
            return(symbol);
        }
示例#3
0
 /// <summary>
 /// Inherits the virtuals from the parent grammar
 /// </summary>
 /// <param name="parent">The parent's grammar</param>
 /// <param name="doClone">Clone the symbols</param>
 private void InheritVirtuals(Grammar parent, bool doClone)
 {
     foreach (Virtual vir in parent.Virtuals)
     {
         if (doClone)
         {
             Virtual clone = new Virtual(vir.ID, vir.Name);
             virtuals.Add(clone.Name, clone);
         }
         else
         {
             if (!virtuals.ContainsKey(vir.Name))
             {
                 AddVirtual(vir.Name);
             }
         }
     }
 }