/*******************************************************************
  The Stream is a queue ADT

  Stream     : string       ->   Stream
             : ()           ->   Stream
             Construct a new Stream - based on input character string
             if specified. Simply create an empty Stream otherwise.

  Put        : Stream, item ->   Stream
             Add an item to the end

  Get        : Stream       ->   item
             Consume from the front

  UnGet      : Stream
             Change our minds about consuming - undo the last Get.

  Peek       : Stream       ->   item
             Look at the next symbol without consuming it

  Line       : Stream       ->   integer
             Return the current line number - this is a 1+count of the
             \n characters consumed so far.

  IsEmpty    : Stream       ->   booleam
             Check if it is empty

  ToString   : Stream       ->   string
             Turn the whole thing into a single string separated by \n


  To be done...reclaim memory after consuming
*********************************************************************/
function Stream(a){
/* Two components, TheArray   - an array or string
                   ThePointer - the position of the next element
*/
if (arguments.length==0)
  this.TheArray = new Array();
else
  this.TheArray = a;
this.ThePointer = 0;
this.LineNumber = 1;
}
function Get(t){
if (typeof(t.TheArray) == "string"){
  if (t.TheArray.charAt(t.ThePointer)=="\n") t.LineNumber++;
  return(t.TheArray.charAt(t.ThePointer++));
  }
else
  return(t.TheArray[t.ThePointer++])
}

function Line(t){
return(t.LineNumber);
}

function Peek(t){
if (typeof(t.TheArray) == "string")
  return(t.TheArray.charAt(t.ThePointer))
else
  return(t.TheArray[t.ThePointer])
}

function Put(t, x){
if (typeof(t.TheArray) == "string")
  t.TheArray += x
else
  t.TheArray[t.TheArray.length] = x
}
function UnGet(t){
t.ThePointer--
}

function IsEmpty(t){
return(t.ThePointer>=t.TheArray.length)
}
function Size(t){return t.TheArray.length;}
function join(t, c){
return(t.TheArray.join(c))
}
function Last(t){
return(t.TheArray[t.TheArray.length-1])
}
function ToString(t){
if (typeof(t.TheArray) == "string")
  return(t.TheArray)
else
  return(t.TheArray.join("\n"));
}
/******************* End of Stream ADT *************************/

