Ejemplo n.º 1
0
        private ConsCell Read()
        {
            if (tokens.Count == 0)
            {
                return(ConsCell.Nil);
            }

            var token = tokens.Dequeue();

            if (token == "(")
            {
                openingParensCount++;
                var car = Read();
                var cdr = Read();
                return(new ConsCell(car, cdr));
            }
            if (token == ")")
            {
                openingParensCount--;
                return(ConsCell.Nil);
            }
            if (token == "'")
            {
                var caar = Atom.Parse("quote");
                var next = Read();
                var cadr = new ConsCell(next.Car, ConsCell.Nil);
                var car  = new ConsCell(caar, cadr);
                var cdr  = next.Cdr;
                return(new ConsCell(car, cdr));
            }
            {
                var car = Atom.Parse(token);
                var cdr = Read();
                return(new ConsCell(car, cdr));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmptyMatcher{TValue, TResult}" /> class.
 /// </summary>
 /// <param name="funcIfConsCell">The function that is executed if this list is a cons cell.</param>
 internal EmptyMatcher(Func <TValue, ConsList <TValue>, TResult> funcIfConsCell)
 {
     this.cell           = null;
     this.isCellPresent  = default;
     this.funcIfConsCell = funcIfConsCell;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmptyMatcher{TValue, TResult}" /> class.
 /// </summary>
 /// <param name="cell">The cell to provide to the function.</param>
 /// <param name="funcIfConsCell">The function that is executed if this list is a cons cell.</param>
 internal EmptyMatcher(ConsCell <TValue> cell, Func <TValue, ConsList <TValue>, TResult> funcIfConsCell)
 {
     this.cell           = cell;
     this.isCellPresent  = true;
     this.funcIfConsCell = funcIfConsCell;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsCellMatcher{TValue, TResult}" /> class.
 /// </summary>
 /// <param name="funcIfEmpty">The function that is executed if this list is empty.</param>
 internal ConsCellMatcher(Func <TResult> funcIfEmpty)
 {
     this.cell          = null;
     this.isCellPresent = false;
     this.funcIfEmpty   = funcIfEmpty;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="ConsCellMatcher{TValue, TResult}" /> class.
 /// </summary>
 /// <param name="cell">The cell to provide to the function.</param>
 /// <param name="funcIfEmpty">The function that is executed if this list is empty.</param>
 internal ConsCellMatcher(ConsCell <TValue> cell, Func <TResult> funcIfEmpty)
 {
     this.cell          = cell;
     this.isCellPresent = true;
     this.funcIfEmpty   = funcIfEmpty;
 }