• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
      • Std/lists
      • Omaps
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
        • Charset-p
        • Strtok!
        • Cases
        • Concatenation
        • Character-kinds
        • Html-encoding
        • Substrings
        • Strtok
        • Equivalences
        • Url-encoding
        • Lines
        • Explode-implode-equalities
        • Ordering
        • Numbers
          • Decimal
          • Hex
          • Octal
            • Parse-octal-from-string
            • Parse-octal-from-charlist
              • Nat-to-oct-chars
              • Oct-digit-chars-value
              • Oct-digit-char-p
              • Take-leading-oct-digit-chars
              • Oct-digit-char-value
              • Oct-digit-char-list*p
              • Oct-digit-char-listp
              • Skip-leading-octal-digits
              • Oct-digit-string-p
              • Nat-to-oct-string
              • Strval8
              • Nat-to-oct-string-list
              • Revappend-nat-to-oct-chars
              • Nonzero-oct-digit-char-p
              • Nat-to-oct-string-size
              • Octal-digit-to-char
            • Binary
          • Pad-trim
          • Coercion
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/osets
        • Std/io
        • Std/basic
        • Std/system
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Octal

    Parse-octal-from-charlist

    Parse a octal number from the beginning of a character list.

    Signature
    (parse-octal-from-charlist x val len) → (mv val len rest)
    Arguments
    x — Characters to read from.
        Guard (character-listp x).
    val — Accumulator for the value of the octal digits we have read so far; typically 0 to start with.
        Guard (natp val).
    len — Accumulator for the number of octal digits we have read; typically 0 to start with.
        Guard (natp len).
    Returns
    val — Value of the initial octal digits as a natural number.
    len — Number of initial octal digits we read.
    rest — The rest of x, past the leading octal digits.

    This is like (parse-nat-from-charlist x val len), but deals with octal digits and returns their octal value.

    Definitions and Theorems

    Function: parse-octal-from-charlist

    (defun parse-octal-from-charlist (x val len)
      (declare (xargs :guard (and (character-listp x)
                                  (natp val)
                                  (natp len))))
      (declare (type unsigned-byte val len))
      (declare (xargs :split-types t))
      (let ((acl2::__function__ 'parse-octal-from-charlist))
        (declare (ignorable acl2::__function__))
        (cond ((atom x)
               (mv (lnfix val) (lnfix len) nil))
              ((oct-digit-char-p (car x))
               (parse-octal-from-charlist
                    (cdr x)
                    (the unsigned-byte
                         (+ (the unsigned-byte
                                 (oct-digit-char-value (car x)))
                            (the unsigned-byte
                                 (ash (the unsigned-byte (lnfix val))
                                      3))))
                    (the unsigned-byte
                         (+ 1 (the unsigned-byte (lnfix len))))))
              (t (mv (lnfix val) (lnfix len) x)))))

    Theorem: val-of-parse-octal-from-charlist

    (defthm val-of-parse-octal-from-charlist
      (equal (mv-nth 0 (parse-octal-from-charlist x val len))
             (+ (oct-digit-chars-value (take-leading-oct-digit-chars x))
                (ash (nfix val)
                     (* 3
                        (len (take-leading-oct-digit-chars x)))))))

    Theorem: len-of-parse-octal-from-charlist

    (defthm len-of-parse-octal-from-charlist
      (equal (mv-nth 1 (parse-octal-from-charlist x val len))
             (+ (nfix len)
                (len (take-leading-oct-digit-chars x)))))

    Theorem: rest-of-parse-octal-from-charlist

    (defthm rest-of-parse-octal-from-charlist
      (equal (mv-nth 2 (parse-octal-from-charlist x val len))
             (skip-leading-octal-digits x)))