public Grammar( string name, Expression top,
						ExpBuilder builder, Grammar parent )
            : base(name,top)
        {
            this.Parent = parent;
            this.Builder = builder;
        }
	public static bool Verify(
		XmlReader document, Grammar grammar, ErrorHandler handler ) {
		
		while(!document.IsStartElement())
			document.Read();
		
		Verifier v = new Verifier(document,grammar.Builder,handler);
		v.Verify(grammar);
		return !v.hadError;
	}
        public static string printGrammar( Grammar grammar )
        {
            using( StringWriter str = new StringWriter() ) {
            ExpPrinter printer = new ExpPrinter(str,-1,false);
            str.Write("(start): ");
            grammar.exp.Visit(printer);
            str.Write("\n");

            foreach( ReferenceExp exp in grammar.NamedPatterns ) {
                str.Write(exp.name);
                str.Write(" : ");
                exp.exp.Visit(printer);
                str.Write("\n");
            }

            return str.ToString();
            }
        }
 public Grammar( Grammar parent, ExpBuilder builder )
     : base(null)
 {
     this.Parent = parent;
     this.Builder = builder;
 }
 protected virtual Expression GrammarElm()
 {
     Grammar n = new Grammar(grammar,Builder);
     grammar = n;
     DivInGrammar();
     grammar = grammar.Parent;
     return n;
 }
        public Grammar parse( XmlReader reader )
        {
            // reset variables
            nsStack.Clear();
            nsStack.Push("");
            dtLibURIStack.Clear();
            baseUriStack.Clear();
            entityURLs.Clear();
            readerStack.Clear();
            readerStack.Push(null);

            PushEntity(reader);
            try {
            // skip xml declaration, DOCTYPE etc.
            while(!reader.IsStartElement())	reader.Read();

            HadError = false;
            Expression exp = ReadExp();
            if( HadError )	return null;	// there was an error.

            if( exp is Grammar )
                return (Grammar)exp;
            else {
                Grammar g = new Grammar(Builder);
                g.exp = exp;
                return g;
            }
            } finally {
            PopEntity();
            }
        }
 public Grammar(Grammar parent, ExpBuilder builder) : base(null)
 {
     this.Parent  = parent;
     this.Builder = builder;
 }
 public Grammar(string name, Expression top,
                ExpBuilder builder, Grammar parent) : base(name, top)
 {
     this.Parent  = parent;
     this.Builder = builder;
 }