• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • 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
      • 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-main

      Wrapper: lex the entire input stream or fail with a good error message.

      Signature
      (lex-main sin) → (mv errmsg tokens sin)
      Arguments
      sin — The sin stobj.
      Returns
      errmsg — nil on success, or a good error message (as a string) on failure.
          Type (or (stringp errmsg) (not errmsg)).
      tokens — Type (tokenlist-p tokens).
      sin — Empty input stream on success, or the remaining part of the input stream on failure.

      Definitions and Theorems

      Function: lex-main

      (defun lex-main (sin)
        (declare (xargs :stobjs (sin)))
        (declare (xargs :guard t))
        (let ((__function__ 'lex-main))
          (declare (ignorable __function__))
          (b* (((mv okp tokens sin) (lex* sin))
               ((when okp) (mv nil tokens sin))
               (errmsg (cat (sin-file sin)
                            ":" (natstr (sin-line sin))
                            ":" (natstr (sin-col sin))
                            ": syntax error near: "
                            (sin-firstn (min 20 (sin-len sin)) sin)
                            (newline-string))))
            (mv errmsg tokens sin))))

      Theorem: return-type-of-lex-main.errmsg

      (defthm return-type-of-lex-main.errmsg
        (b* (((mv ?errmsg ?tokens ?sin)
              (lex-main sin)))
          (or (stringp errmsg) (not errmsg)))
        :rule-classes :type-prescription)

      Theorem: tokenlist-p-of-lex-main.tokens

      (defthm tokenlist-p-of-lex-main.tokens
        (b* (((mv ?errmsg ?tokens ?sin)
              (lex-main sin)))
          (tokenlist-p tokens))
        :rule-classes :rewrite)

      Theorem: tokenlist-all-text-of-lex-main

      (defthm tokenlist-all-text-of-lex-main
        (b* (((mv errmsg tokens ?new-sin)
              (lex-main sin)))
          (implies (not errmsg)
                   (equal (tokenlist-all-text tokens)
                          (implode (strin-left sin))))))