• 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

    Lex-punctuation

    Match punctuation characters to create a :punctuation token.

    Signature
    (lex-punctuation sin) → (mv tok sin)
    Arguments
    sin — The sin stobj.
    Returns
    tok — A punctuation token taken from the start of the input stream, or nil if the input stream does not start with some valid punctuation.
        Type (equal (token-p tok) (if tok t nil)).
    sin — The remaining input stream, with the leading digits removed.

    It's important to put the ++ and -- operators first here. For instance, if + came first, then we'd end up converting ++ into two separate + tokens.

    Definitions and Theorems

    Function: lex-punctuation

    (defun lex-punctuation (sin)
      (declare (xargs :stobjs (sin)))
      (declare (xargs :guard t))
      (let ((__function__ 'lex-punctuation))
        (declare (ignorable __function__))
        (b* (((mv match sin)
              (sin-match-some-lit '("++" "--" ";" "+" "-" "*" "/")
                                  sin))
             ((unless match) (mv nil sin)))
          (mv (make-token :type :punctuation
                          :text match)
              sin))))

    Theorem: return-type-of-lex-punctuation.tok

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

    Theorem: lex-punctuation-progress-weak

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

    Theorem: lex-punctuation-progress-strong

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

    Theorem: lex-punctuation-reconstruction

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