internal Object Read(LocTextReader t)
 {
     return reader.Read(t);
 }
 internal Object readSymbolOrNumber(LocTextReader t, Int32 ch, Boolean firstInForm)
 {
     StringBuilder b = new StringBuilder();
     b.Append((Char)ch);
     Boolean complete = false;
     while (!complete)
     {
         ch = t.Peek();
         if (ch == -1)
             complete = true;
         else if (Char.IsWhiteSpace((Char)ch))
             complete = true;
         else
         {
             ReaderMacro rm = (ReaderMacro)macroTable[(Char)ch];
             if (rm != null && rm.isTerminating)
                 complete = true;
             else
             {
                 t.Read();
                 b.Append((Char)ch);
             }
         }
     }
     return parseSymbolOrNumber(b.ToString(), firstInForm);
 }
 internal Object Load(LocTextReader t)
 {
     Object expr = null;
     do
     {
         Int32 line = t.line;
         expr = Read(t);
         if (!Eof(expr))
         {
             try
             {
                 eval(expr, globalenv);
             }
             catch (Exception ex)
             {
                 throw BacktraceException.push(ex,
                                                         new BacktraceFrame(new Loc(t.file, line), "when evaluating ", expr), this);
             }
         }
     } while (!Eof(expr));
     return true;
 }
        internal Cons readDelimitedList(LocTextReader t, Int32 delim)
        {
            Cons ret = null;
            Cons tail = null;

            Int32 ch = t.Peek();
            while (Char.IsWhiteSpace((Char)ch))
            {
                t.Read();
                ch = t.Peek();
            }
            while (ch != delim)
            {
                Object o = doRead(t, delim == ')' && ret == null);
                if (eof(o))
                {
                    throw new Exception("Read error - eof found before matching: "
                                              + (Char)delim + "\n File: " + t.file + ", line: " + t.line);
                }
                EndDelimiter ed = o as EndDelimiter;
                if (ed != null)
                {
                    if (ed.delim == delim)
                    {
                        return ret;
                    }
                    else
                        throw new Exception("Read error - read unmatched: " + ed.delim
                                                  + "\n File: " + t.file + ", line: " + t.line);
                }
                Cons link = new Cons(o, null);
                if (delim == ')' && ret == null && o is CompositeSymbol)
                {
                    ret = ((CompositeSymbol)o).symbolAsList;
                    tail = ret.rest;
                }
                else if (ret == null)
                {
                    ret = tail = link;
                }
                else
                {
                    tail.rest = link;
                    tail = link;
                }
                ch = t.Peek();
                while (Char.IsWhiteSpace((Char)ch))
                {
                    t.Read();
                    ch = t.Peek();
                }
            }

            //eat delim
            t.Read();
            return ret;
        }
 internal object Read(LocTextReader t)
 {
     Object result = doRead(t, false);
     if (result is EndDelimiter)
         throw new Exception("Read error - read unmatched: " + ((EndDelimiter)result).delim);
     return result;
 }
 internal void eatMultiComment(LocTextReader t)
 {
     Int32 ch = t.Peek();
     while (ch != -1 && ch != '#')
     {
         t.Read();
         ch = t.Peek();
     }
     if (ch == '#')
         t.Read();
 }
 internal void eatComment(LocTextReader t)
 {
     Int32 ch = t.Peek();
     while (ch != -1 && ch != '\n' && ch != '\r')
     {
         t.Read();
         ch = t.Peek();
     }
     if (ch != -1 && ch != '\n' && ch != '\r')
         t.Read();
 }
 internal Object doRead(LocTextReader t, Boolean firstInForm)
 {
     Int32 ch = t.Read();
     while (Char.IsWhiteSpace((Char)ch))
     {
         ch = t.Read();
     }
     if (ch == -1)
     {
         //return null;
         //return Symbol.EOF;
         return EOF_MARKER;
     }
     if (ch == '#')
     {
         eatMultiComment(t);
         return doRead(t, firstInForm);
     }
     if (ch == ';')
     {
         eatComment(t);
         return doRead(t, firstInForm);
     }
     ReaderMacro rm = (ReaderMacro)macroTable[(Char)ch];
     if (rm != null)
     {
         return rm.func(t, (Char)ch);
     }
     else
     {
         return readSymbolOrNumber(t, ch, firstInForm);
     }
 }