示例#1
0
        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 Load(LocTextReader t)
        {
            Object expr = null;

            do
            {
                Int32 line = t.line;
                expr = Read(t);
                if (!Eof(expr))
                {
                    try
                    {
                        eval(expr, globalenv);
                    }
                    catch (Exception ex)
                    {
                        Loc loc = new Loc(t.file, line);
                        Console.Error.WriteLine(ex);
                        Console.Error.WriteLine("loc=" + loc);

                        Console.ReadLine();
                        throw BacktraceException.push(ex,
                                                      new BacktraceFrame(loc, "when evaluating ", expr), this);
                    }
                }
            }while(!Eof(expr));
            return(true);
        }
示例#3
0
        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));
        }
示例#4
0
        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));
            }
        }
示例#5
0
        internal Object ReadBackQuote(params Object[] args)
        {
            LocTextReader t    = (LocTextReader)args[0];
            Int32         line = t.line;
            Object        ret  = Cons.MakeList(interpreter.BACKQUOTE, doRead(t, false));

            //record the location
            locTable[ret] = new Loc(t.file, line);
            return(ret);
        }
示例#6
0
        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);
        }
示例#7
0
        internal Object ReadVector(params Object[] args)
        {
            LocTextReader t     = (LocTextReader)args[0];
            Int32         line  = t.line;
            Cons          largs = readDelimitedList(t, ']');
            Object        ret   = new Cons(interpreter.VECTOR, largs);

            //record the location
            locTable[ret] = new Loc(t.file, line);
            return(ret);
        }
示例#8
0
        internal Object ReadEndDelimiter(params Object[] args)
        {
            LocTextReader t = (LocTextReader)args[0];
            //so we can complain
            EndDelimiter ed = new EndDelimiter();

            //Char c = (Char)args[1];//t.Read();
            ed.delim = (Char)args[1];    //t.Read();
            return(ed);
            //throw new Exception("Read error - read unmatched: " + c);
        }
示例#9
0
        internal Object ReadList(params Object[] args)
        {
            LocTextReader t    = (LocTextReader)args[0];
            Int32         line = t.line;
            Object        ret  = readDelimitedList(t, ')');

            //record the location
            if (ret != null)
            {
                locTable[ret] = new Loc(t.file, line);
            }
            return(ret);
        }
示例#10
0
        internal void eatMultiComment(LocTextReader t)
        {
            Int32 ch = t.Peek();

            while (ch != -1 && ch != '#')
            {
                t.Read();
                ch = t.Peek();
            }
            if (ch == '#')
            {
                t.Read();
            }
        }
示例#11
0
        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();
            }
        }
示例#12
0
        internal void eatComment(LocTextReader t)
        {
            Int32 ch = t.Peek();

            while (ch != -1 && ch != '\n' && ch != '\r')
            {
                t.Read();
                ch = t.Peek();
            }
            // MEH: Why? Should never be true, or while would loop.
            //if(ch != -1 && ch != '\n' && ch != '\r')
            //	t.Read();
            // MEH: Guessing this was the intention:
            while (ch == '\n' || ch == '\r')
            {
                t.Read();
                ch = t.Peek();
            }
        }
示例#13
0
        internal Object ReadUnquote(params Object[] args)
        {
            LocTextReader t    = (LocTextReader)args[0];
            Int32         line = t.line;
            Int32         ch   = t.Peek();
            Object        ret  = null;

            if (ch == '@')
            {
                t.Read();
                ret = Cons.MakeList(interpreter.UNQUOTE_SPLICING, doRead(t, false));
            }
            else
            {
                ret = Cons.MakeList(interpreter.UNQUOTE, doRead(t, false));
            }
            //record the location
            locTable[ret] = new Loc(t.file, line);
            return(ret);
        }
        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);
        }
示例#15
0
        internal Object doRead(LocTextReader t, Boolean firstInForm)
        {
            //MEH: Converted the following from a while loop, and avoid checked build issues with ((Char)-1).
            Int32 ch;    // = t.Read();

            do
            {
                ch = t.Read();
                if (ch == -1)
                {
                    //return null;
                    //return Symbol.EOF;
                    return(EOF_MARKER);
                }
            }while(Char.IsWhiteSpace((Char)ch));
            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));
            }
        }
 internal Object Read(LocTextReader t)
 {
     return reader.Read(t);
 }
 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;
 }
示例#18
0
	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)
					{
                        Loc loc = new Loc(t.file, line);
					    Console.Error.WriteLine(ex);
                        Console.Error.WriteLine("loc=" + loc);

                        Console.ReadLine();
					throw BacktraceException.push(ex,
                                                            new BacktraceFrame(loc, "when evaluating ", expr), this);
					}
				}
			}while(!Eof(expr));
		return true;
		}
示例#19
0
        internal Object ReadString(params Object[] args)
        {
            StringBuilder b    = new StringBuilder();
            LocTextReader t    = (LocTextReader)args[0];
            Int32         line = t.line;
            //eat the double-quote
            //t.Read();
            //Int32 ch = t.Peek();
            Int32 ch = t.Read();

            while (ch != '"')
            {
                if (ch == -1)
                {
                    throw new Exception("Read error - eof found before matching: \""
                                        + "\n File: " + t.file + ", line: " + t.line);
                }
                //eat it
                //t.Read();
                if (ch == '\\')         //escape
                {
                    ch = t.Read();
                    if (ch == -1)
                    {
                        throw new Exception("Read error - eof found before matching: \""
                                            + "\n File: " + t.file + ", line: " + t.line);
                    }
                    switch (ch)
                    {
                    case 't':
                        ch = '\t';
                        break;

                    case 'r':
                        ch = '\r';
                        break;

                    case 'n':
                        ch = '\n';
                        break;

                    case '\\':
                        break;

                    case '"':
                        break;

                    default:
                        throw new Exception("Unsupported escape character: \\" + (Char)ch
                                            + "\n File: " + t.file + ", line: " + t.line);
                    }
                }
                b.Append((Char)ch);
                //ch = t.Peek();
                ch = t.Read();
            }
            //eat the trailing quote
            //t.Read();
            Object ret = b.ToString();

            //record the location
            locTable[ret] = new Loc(t.file, line);
            return(ret);
        }
示例#20
0
	internal void eatComment(LocTextReader t)
		{
		Int32 ch = t.Peek();
		while(ch != -1 && ch != '\n' && ch != '\r')
			{
			t.Read();
			ch = t.Peek();
			}
		// MEH: Why? Should never be true, or while would loop.
		//if(ch != -1 && ch != '\n' && ch != '\r')
		//	t.Read();
		// MEH: Guessing this was the intention:
		while(ch == '\n' || ch == '\r')
			{
			t.Read();
			ch = t.Peek();
			}
		}
示例#21
0
 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);
     }
 }
示例#22
0
 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();
 }
示例#23
0
 internal void eatMultiComment(LocTextReader t)
 {
     Int32 ch = t.Peek();
     while(ch != -1 && ch != '#')
     {
     t.Read();
     ch = t.Peek();
     }
     if(ch == '#')
     t.Read();
 }
示例#24
0
 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;
 }
示例#25
0
        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;
        }
示例#26
0
 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 Read(LocTextReader t)
 {
     return(reader.Read(t));
 }
示例#28
0
	internal Object doRead(LocTextReader t,Boolean firstInForm)
		{
		//MEH: Converted the following from a while loop, and avoid checked build issues with ((Char)-1).
		Int32 ch;// = t.Read();
		do
			{
			ch = t.Read();
			if(ch == -1)
				{
				//return null;
				//return Symbol.EOF;
				return EOF_MARKER;
				}
			}
		while(Char.IsWhiteSpace((Char)ch));
		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);
			}
		}