• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Bitcoin
        • Ethereum
        • Yul
          • Transformations
          • Language
            • Abstract-syntax
            • Dynamic-semantics
            • Concrete-syntax
              • Lexer
              • Parser
                • Parse-keyword
                • Parse-variable-declaration
                  • Parse-symbol
                  • Parse-literal
                  • Parse-identifier
                  • Hex-chars-and-uscores-to-hex-string-rest-element-list
                  • Parse-assignment-statement
                  • Parse-identifier-and-open-paren
                  • Parse-*-comma-identifier
                  • Parse-*-.-identifier
                  • Parse-continue-statement
                  • Parse-*-comma-path
                  • Parse-path
                  • Parse-leave-statement
                  • Parse-break-statement
                  • Cst2ast-hex-string
                  • Cst2ast-string-literal-content
                  • Cst2ast-escape-sequence
                  • Cst2ast-string-literal-contents
                  • Cst2ast-quoted-printable
                  • Parse-yul
                  • Cst2ast-string-literal
                  • Parse-yul-bytes
                  • Cst2ast-hex-number
                  • Cst2ast-uhhhh
                  • Cst2ast-literal-kind
                  • Cst2ast-decimal-number
                  • Cst2ast-xhh
                  • Cst2ast-single-char
                  • Cst2ast-boolean
                  • Parse-*-case-clause
                  • Looks-like-hex-string-fringe
                  • Cst2ast-hex-digit-char-list
                  • Parse-*-statement
                  • Parse-*-comma-expression
                  • Parse-switch-statement
                  • Parse-if-statement
                  • Parse-for-statement
                  • Parse-expression
                  • Parse-case-clause
                  • Parse-fundef
                  • Parse-function-call
                  • Parse-block
                  • *single-quote-tree-list*
                  • *double-quote-tree-list*
                  • *yul-keywords*
                  • *single-quoted-content-rulenames*
                  • *list-leafterm-x*
                  • *list-leafterm-u*
                  • *list-leafterm-92*
                  • *double-quoted-content-rulenames*
                  • *yul-symbols*
                • Grammar-old
                • Grammar
                • Tokenizer
              • Static-soundness
              • Static-semantics
              • Errors
            • Yul-json
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Parser

    Parse-variable-declaration

    Attempts to eat a variable declaration and build a statement AST node of kind :variable-single or :variable-multi.

    Signature
    (parse-variable-declaration tokens) 
      → 
    (mv result-ast tokens-after-statement)
    Arguments
    tokens — Guard (abnf::tree-listp tokens).
    Returns
    result-ast — Type (statement-resultp result-ast).
    tokens-after-statement — Type (abnf::tree-listp tokens-after-statement).

    The syntax diagram for `yul-variable-declaration' allows two ways of parsing a variable declaration with a single identifier and an initialization of a function call.For example, let x := s(0).

    The initialization can be a yul-expression which can be a yul-function-call, or the initialization can be a yul-function-call directly.Although the syntax does not differ, and a grammar does not dictate the AST that is built, we still must decide what to build.We decided to build an expression of kind :funcall containing a funcall object whenever there is a single identifier.

    This treatment is consistent with the handling of single and muli-assignmebnts, but in that case the syntax diagram dictates at least two yul-path instances prior to a direct yul-function-call.

    Definitions and Theorems

    Function: parse-variable-declaration

    (defun parse-variable-declaration (tokens)
      (declare (xargs :guard (abnf::tree-listp tokens)))
      (let ((__function__ 'parse-variable-declaration))
        (declare (ignorable __function__))
        (b* (((mv ?key1 tokens-after-let)
              (parse-keyword "let" tokens))
             ((when (reserrp tokens-after-let))
              (mv (reserrf (cons "no variable decl here" tokens))
                  nil))
             ((mv let-var-1 tokens-after-let-var-1)
              (parse-identifier tokens-after-let))
             ((when (null let-var-1))
              (mv (reserrf (cons "no variable decl here 2" tokens))
                  nil))
             ((when (reserrp tokens-after-let-var-1))
              (mv (reserrf (cons "no variable decl here 3" tokens))
                  nil))
             ((mv rest-identifiers
                  tokens-after-rest-identifiers)
              (parse-*-comma-identifier tokens-after-let-var-1))
             (tokens-after-init-symbol
                  (parse-symbol ":=" tokens-after-rest-identifiers))
             ((mv init-ast tokens-final)
              (if (reserrp tokens-after-init-symbol)
                  (mv nil tokens-after-rest-identifiers)
                (b* (((mv init-ast tokens-after-init)
                      (if (null rest-identifiers)
                          (parse-expression tokens-after-init-symbol)
                        (parse-function-call tokens-after-init-symbol)))
                     ((when (reserrp init-ast))
                      (mv nil tokens-after-rest-identifiers)))
                  (mv init-ast tokens-after-init)))))
          (mv (if (null rest-identifiers)
                  (make-statement-variable-single :name let-var-1
                                                  :init init-ast)
                (make-statement-variable-multi
                     :names (cons let-var-1 rest-identifiers)
                     :init init-ast))
              tokens-final))))

    Theorem: statement-resultp-of-parse-variable-declaration.result-ast

    (defthm statement-resultp-of-parse-variable-declaration.result-ast
      (b* (((mv ?result-ast ?tokens-after-statement)
            (parse-variable-declaration tokens)))
        (statement-resultp result-ast))
      :rule-classes :rewrite)

    Theorem: tree-listp-of-parse-variable-declaration.tokens-after-statement

    (defthm
        tree-listp-of-parse-variable-declaration.tokens-after-statement
      (b* (((mv ?result-ast ?tokens-after-statement)
            (parse-variable-declaration tokens)))
        (abnf::tree-listp tokens-after-statement))
      :rule-classes :rewrite)

    Theorem: len-of-parse-variable-declaration-<

    (defthm len-of-parse-variable-declaration-<
      (b* (((mv ?result-ast ?tokens-after-statement)
            (parse-variable-declaration tokens)))
        (implies (not (reserrp result-ast))
                 (< (len tokens-after-statement)
                    (len tokens))))
      :rule-classes :linear)