• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
      • Io
      • Defttag
      • Sys-call
      • Save-exec
      • Quicklisp
      • Std/io
      • Oslib
      • Bridge
      • Clex
        • Example-lexer
          • Token-p
          • Lex-punctuation
          • Lex-id/keyword
          • Lex-string
          • Lex-whitespace
          • Lex-comment
          • Lex1
            • Lex-main
            • Lex*
            • Tokenlist-p
            • Letter-char-p
            • Idtail-char-p
            • Whitespace-char-p
            • Number-char-p
            • Tokentype-p
            • Lex*-exec
            • Newline-string
          • Sin
          • Matching-functions
          • Def-sin-progress
        • Tshell
        • Unsound-eval
        • Hacker
        • ACL2s-interface
        • Startup-banner
        • Command-line
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Example-lexer

    Lex1

    Lex a single token from the input stream.

    Signature
    (lex1 sin) → (mv tok sin)
    Arguments
    sin — The sin stobj, which we assume still has text remaining.
        Guard (not (sin-endp sin)).
    Returns
    tok — The first token from the start of the input stream, or nil on failure.
        Type (equal (token-p tok) (if tok t nil)).
    sin — The remaining input stream, with the leading token removed.

    Definitions and Theorems

    Function: lex1

    (defun lex1 (sin)
      (declare (xargs :stobjs (sin)))
      (declare (xargs :guard (not (sin-endp sin))))
      (let ((__function__ 'lex1))
        (declare (ignorable __function__))
        (b* ((char1 (sin-car sin))
             ((when (char-in-charset-p char1 (whitespace-chars)))
              (lex-whitespace sin))
             ((when (char-in-charset-p char1 (letter-chars)))
              (lex-id/keyword sin))
             ((when (sin-matches-p "//" sin))
              (lex-comment sin)))
          (lex-punctuation sin))))

    Theorem: return-type-of-lex1.tok

    (defthm return-type-of-lex1.tok
      (b* (((mv ?tok ?sin) (lex1 sin)))
        (equal (token-p tok) (if tok t nil)))
      :rule-classes :rewrite)

    Theorem: lex1-progress-weak

    (defthm lex1-progress-weak
      (mv-let (tok new-sin)
              (lex1 sin)
        (declare (ignorable tok new-sin))
        (<= (len (strin-left new-sin))
            (len (strin-left sin))))
      :rule-classes ((:rewrite) (:linear)))

    Theorem: lex1-progress-strong

    (defthm lex1-progress-strong
      (mv-let (tok new-sin)
              (lex1 sin)
        (declare (ignorable tok new-sin))
        (implies tok
                 (< (len (strin-left new-sin))
                    (len (strin-left sin)))))
      :rule-classes ((:rewrite) (:linear)))

    Theorem: lex1-reconstruction

    (defthm lex1-reconstruction
      (b* (((mv tok new-sin) (lex1 sin)))
        (implies tok
                 (equal (append (explode (token->text tok))
                                (strin-left new-sin))
                        (strin-left sin)))))