• 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-id/keyword

    Match identifier characters to create an :id or :keyword token, as appropriate.

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

    Definitions and Theorems

    Function: lex-id/keyword

    (defun lex-id/keyword (sin)
      (declare (xargs :stobjs (sin)))
      (declare (xargs :guard t))
      (let ((__function__ 'lex-id/keyword))
        (declare (ignorable __function__))
        (b* (((when (sin-endp sin)) (mv nil sin))
             (car (sin-car sin))
             ((unless (char-in-charset-p car (letter-chars)))
              (mv nil sin))
             ((mv match sin)
              (sin-match-charset* (idtail-chars) sin))
             ((when (or (equal match "void")
                        (equal match "int")
                        (equal match "float")))
              (mv (make-token :type :keyword :text match)
                  sin)))
          (mv (make-token :type :id :text match)
              sin))))

    Theorem: return-type-of-lex-id/keyword.tok

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

    Theorem: lex-id/keyword-progress-weak

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

    Theorem: lex-id/keyword-progress-strong

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

    Theorem: lex-id/keyword-reconstruction

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