• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • Proof-checker-array
      • Soft
      • C
      • Farray
      • Rp-rewriter
      • Instant-runoff-voting
      • Imp-language
      • Sidekick
      • Leftist-trees
      • Java
      • Taspi
      • Bitcoin
      • Riscv
      • Des
      • Ethereum
      • X86isa
      • Sha-2
      • 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
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Parser

    Parse-symbol

    Attempts to eat the named symbol, returning either the list of remaining tokens or a reserr.

    Signature
    (parse-symbol symbol tokens) → tokens-after-symbol-or-reserr
    Arguments
    symbol — Guard (stringp symbol).
    tokens — Guard (abnf::tree-listp tokens).
    Returns
    tokens-after-symbol-or-reserr — Type (abnf::tree-list-resultp tokens-after-symbol-or-reserr).

    parse-symbol does not build any AST on its own, since there is no Yul AST node class whose surface syntax can consist solely of a single symbol.

    In this context, symbol is a nonterminal in the ABNF grammar for Yul, and its alternatives are terminal symbols. See grammar.abnf.

    Parsing a symbol as a concrete syntax tree means we look for a nonleaf tree where the rulename is "symbol" and the leafterm has the bytes (ASCII codes) of the terminal symbol's string.

    Definitions and Theorems

    Function: parse-symbol

    (defun parse-symbol (symbol tokens)
     (declare (xargs :guard (and (stringp symbol)
                                 (abnf::tree-listp tokens))))
     (let ((__function__ 'parse-symbol))
      (declare (ignorable __function__))
      (if
       (not (member-equal symbol *yul-symbols*))
       (prog2$
        (er
          hard? 'top-level
          (string-append
               "parse-symbol called on something not in *yul-symbols*: "
               symbol))
        (reserrf (cons "program logic error" tokens)))
       (b*
        (((when (endp tokens))
          (reserrf
            (cons (string-append
                       "ran out of tokens when trying to parse symbol: "
                       symbol)
                  tokens)))
         (putative-symbol-tree (first tokens))
         ((unless
           (and
             (abnf::tree-case putative-symbol-tree :nonleaf)
             (equal (abnf::tree-nonleaf->rulename? putative-symbol-tree)
                    (abnf::rulename "symbol"))))
          (reserrf (cons "token is not a symbol" tokens)))
         (branches (abnf::tree-nonleaf->branches putative-symbol-tree))
         ((unless (and (listp branches)
                       (equal (len branches) 1)
                       (listp (car branches))
                       (equal (len (car branches)) 1)
                       (abnf::treep (caar branches))
                       (abnf::tree-case (caar branches)
                                        :leafterm)))
          (prog2$
           (er
            hard? 'top-level
            (string-append
             "symbol token seems to have the wrong structure for symbol:"
             symbol))
           (reserrf (cons "cst structure error" tokens))))
         (leafterm-nats (abnf::tree-leafterm->get (caar branches)))
         ((unless (unsigned-byte-listp 8 leafterm-nats))
          (prog2$
           (er
            hard? 'top-level
            (string-append
                "unexpected type of leafterm nats when parsing symbol: "
                symbol))
           (reserrf (cons "cst structure error 2" tokens))))
         (terminal-symbol (nats=>string leafterm-nats))
         ((unless (equal symbol terminal-symbol))
          (reserrf (cons (concatenate 'string
                                      "looking for symbol: '"
                                      symbol "', but received symbol: '"
                                      terminal-symbol "'")
                         tokens))))
        (abnf::tree-list-fix (rest tokens))))))

    Theorem: tree-list-resultp-of-parse-symbol

    (defthm tree-list-resultp-of-parse-symbol
      (b* ((tokens-after-symbol-or-reserr (parse-symbol symbol tokens)))
        (abnf::tree-list-resultp tokens-after-symbol-or-reserr))
      :rule-classes :rewrite)

    Theorem: len-of-parse-symbol-<

    (defthm len-of-parse-symbol-<
     (b* ((?tokens-after-symbol-or-reserr (parse-symbol symbol tokens)))
       (implies (not (reserrp tokens-after-symbol-or-reserr))
                (< (len tokens-after-symbol-or-reserr)
                   (len tokens))))
     :rule-classes :linear)