예제 #1
0
 public Object Read(LocTextReader t)
 {
     return InnerReader.Read(t);
 }
예제 #2
0
 protected 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);
 }
예제 #3
0
        public Object Load(LocTextReader t)
        {
            Object expr = null;
            do {
                Int32 line = t.Line;
                expr = Read(t);

                if (!Eof(expr)) {
                    try {
                        Eval(expr, GlobalEnvironment);
                    } catch (Exception ex) {
                        throw BacktraceException.Push(ex, new BacktraceFrame(new Location(t.File, line), "when evaluating ", expr), this);
                    }
                }
            } while (!Eof(expr));
            return true;
        }
예제 #4
0
        protected 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 LispException("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 LispException("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;
        }
예제 #5
0
 protected void EatMultiComment(LocTextReader t)
 {
     Int32 ch = t.Peek();
     while (ch != -1 && ch != '#') {
         t.Read();
         ch = t.Peek();
     }
     if (ch == '#')
         t.Read();
 }
예제 #6
0
 protected 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();
 }
예제 #7
0
 //.........................................................................
 protected 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);
     }
 }
예제 #8
0
 public object Read(LocTextReader t)
 {
     Object result = DoRead(t, false);
     if (result is EndDelimiter)
         throw new LispException("Read error - read unmatched: " + ((EndDelimiter)result).Delim);
     return result;
 }